I asked this question [on Mathematics SE](https://math.stackexchange.com/questions/2801536/isomorphism-in-homology) three days ago, but didn't get the answer.

$\require{AMScd}$Let $G, H, K$ be groups and suppose that we have a diagram
$$\begin{CD}
G @>f_1>> H\\
@Vg_1VV\\
K
\end{CD}
$$
where morphisms $f_1$ and $g_1$ induce isomorphism in homology. Can one builds a group $U$ with the properties
<ol>
<li>The following square commutes:
$$\begin{CD}
G @>f_1>> H\\
@Vg_1VV @VVg_2V\\
K @>>f_2> U
\end{CD}
$$
<li>$g_2$ and $f_2$ induce isomorphism in homology.
</ol>

I tried to prove that $U:=K*_G H$ will be such a group. I used Mayer-Vietoris sequence, but it doesn't seem to be working.