Let $G$ be a group and $\{x_1,x_2,\ldots,x_n\}$ a set of its elements, such that for any group $F$ and any set $\{y_1,y_2,\ldots,y_n\}$ of elements of $F$ there is one and only one homomorphism $h: G \rightarrow F$ such that $h(x_i)=y_i$ for $i=1,\ldots,n$. Then $G$ is freely generated by the set $\{x_1,x_2,\ldots,x_n\}$.
The other way round is quite easy to prove. To prove this one, the first thing that comes to one's mind is of course to let $F$ be the subgroup of $G$ generated by the set $\{x_1,x_2,\ldots,x_n\}$, and the elements $y_i$ to be the $x_i$ themselves. This yields a homomorphism $h: G \rightarrow F$ such that $h_{|F}=id_F$. This in turn yields that $G$ is the semidirect product of $F$ and $ker(h)$. I miss some point, and I can't get any further.
Well, folks, I beg your pardon for bothering you with such a trivial question. I can't believe I didn't see the answer at once. Sometimes one just can't see the most elementary things. Please, correct me if the following proof is wrong.
Let $F$ and $h$ be as stated before, $i$ the inclusion of $F$ into $G$. Then $k=i\circ h$ is an endomorphism of $G$ such that $k(x_i)=x_i$ for $i=1,\ldots,n$. If $F\neq G$ and $i_G$ is the identity of $G$ then $k \neq i_G$. But by hypothesis $i_G$ is the only endomorphism $f$ of $G$ such that $f(x_i)=x_i$ for $i=1,\ldots,n$.
I'd wanted to take $F$ to be a free group on $x_1,...,x_n$, but to get around your restriction of not assuming that there are free groups here is a different approach. Consider a presentation for $G$ as $\langle x_1,...,x_n,(w_m)_{m\in M}: (r_j)_{j\in J}\rangle$ where the $r_j$ are relations. Suppose some subset $S$ of the $r_j$ involve only the $x_i$. Then there exists no homomorphism fixing the $x_i$ from $G$ to the group with presentation identical to that of $G$ except for the removal of relations in $S$. This contradicts our assumption, and so $S$ is empty, that is, all the relations involve some of the $w_j$. So we've shown that the subgroup of $G$ generated by the $x_i$ is free on them.
What remains is to show that $M$ is empty. Construct a group $H$ generated by the $w_m$ with relations gotten from the $r_j$ by setting $x_i=e.$ Consider the list $y_1=...=y_n=e$ of elements of $H$. The trivial homomorphism $G\to H$ sending every element to $e$ is certainly a homomorphism of the kind required by the assumption about $G$. But I claim the map $\varphi$ described by $\varphi(x_1)=...=\varphi(x_n)=e,\varphi(w_m)=w_m\forall m\in M$ is also a homomorphism, which obviously satisfies the condition on the image of the $x_i$. Indeed, it's enough to check that $\varphi$ sends every relation to $e$. But since all the $x_i$ are sent to $e$ already the only remaining nontrivial relations are those we cooked into the definition of $H$. So we apparently have two different homomorphisms to $H$ sending the $x_i$ to $e,$ which would contradict our assumption that such a homomorphism should be unique. Thus in fact each $w_m=e$ in $H$ and thus so too in $G$.