  We show that a domain is an extension domain for a Haj\l asz-Besov or for a
Haj\l asz-Triebel-Lizorkin space if and only if it satisfies a measure density
condition. We use a modification of the Whitney extension where integral
averages are replaced by median values, which allows us to handle also the case
$0<p<1$. The necessity of the measure density condition is derived from
embedding theorems; in the case of Haj\l asz-Besov spaces we apply an optimal
Lorentz-type Sobolev embedding theorem which we prove using a new interpolation
result. This interpolation theorem says that Haj\l asz-Besov spaces are
intermediate spaces between $L^p$ and Haj\l asz-Sobolev spaces. Our results are
proved in the setting of a metric measure space, but most of them are new even
in the Euclidean setting, for instance, we obtain a characterization of
extension domains for classical Besov spaces $B^s_{p,q}$, $0<s<1$,
$0<p<\infty$, $0<q\le\infty$, defined via the $L^p$-modulus of smoothness of a
function.
