Let $G_1, G_1$, and $H$ be groups. Let $f_1: G_1 \to H$ and $f_2: G_2 \to H$ be group homomorphisms.
Define the subset $M$ of $G_1 \times G_2$ to be
\[M=\{(a_1, a_2) \in G_1\times G_2 \mid f_1(a_1)=f_2(a_2)\}.\]

Suppose that $(a_1, a_2), (b_1, b_2) \in M$.
By definition, we have
\[f_1(a_1)=f_2(a_2) \text{ and } f_1(b_1)=f_2(b_2). \tag{*}\]
The product of $(a_1, a_2)$ and $(b_1, b_2)$ is
\[(a_1, a_2)\cdot (b_1, b_2)=(a_1b_1, a_2b_2).\]

We want to prove that this is in $M$. To see this, note that we have
\begin{align*}
f_1(a_1b_1)&=f_1(a_1)f_1(b_1) && \text{($f_1$ is a homomorphism)}\\
&=f_2(a_2)f_2(b_2) && \text{(by (*))}\\
&=f_2(a_2b_2) && \text{($f_2$ is a homomorphism)}.
\end{align*}

Therefore we have obtained
\[f_1(a_1b_1)=f_2(a_2b_2),\]
and the product $(a_1b_1, a_2b_2)$ is in $M$ by definition.

$M$ is closed under inverses

We next prove that if $(a_1, a_2)\in M$ then the inverse
\[(a_1, a_2)^{-1}=(a_1^{-1}, a_2^{-1})\]
is also in $M$.

Since $(a_1, a_2)\in M$, we have
\[f_1(a_1)=f_2(a_2). \tag{**}\]
Then we have
\begin{align*}
f_1(a_1^{-1})&=(f_1(a_1))^{-1} && \text{($f_1$ is a homomorphism)}\\
&=(f_2(a_2))^{-1} && \text{ (by (**))}\\
&=f_2(a_2^{-1}) && \text{($f_2$ is a homomorphism)}.
\end{align*}
Thus by definition the inverse $(a_1^{-1}, a_2^{-1})$ is in $M$.

Since $M$ is closed under the group operation and inverses, it is a subgroup of $G_1 \times G_2$.

Comment.

In category theory, the subgroup $M$ in the problem is called a pullback of homomorphisms $f_1: G_1 \to H$ and $f_2: G_2 \to H$.

A Group Homomorphism is Injective if and only if Monic
Let $f:G\to G'$ be a group homomorphism. We say that $f$ is monic whenever we have $fg_1=fg_2$, where $g_1:K\to G$ and $g_2:K \to G$ are group homomorphisms for some group $K$, we have $g_1=g_2$.
Then prove that a group homomorphism $f: G \to G'$ is injective if and only if it is […]

Surjective Group Homomorphism to $\Z$ and Direct Product of Abelian Groups
Let $G$ be an abelian group and let $f: G\to \Z$ be a surjective group homomorphism.
Prove that we have an isomorphism of groups:
\[G \cong \ker(f)\times \Z.\]
Proof.
Since $f:G\to \Z$ is surjective, there exists an element $a\in G$ such […]

Torsion Subgroup of an Abelian Group, Quotient is a Torsion-Free Abelian Group
Let $A$ be an abelian group and let $T(A)$ denote the set of elements of $A$ that have finite order.
(a) Prove that $T(A)$ is a subgroup of $A$.
(The subgroup $T(A)$ is called the torsion subgroup of the abelian group $A$ and elements of $T(A)$ are called torsion […]

A Group Homomorphism and an Abelian Group
Let $G$ be a group. Define a map $f:G \to G$ by sending each element $g \in G$ to its inverse $g^{-1} \in G$.
Show that $G$ is an abelian group if and only if the map $f: G\to G$ is a group homomorphism.
Proof.
$(\implies)$ If $G$ is an abelian group, then $f$ […]

Group Homomorphism Sends the Inverse Element to the Inverse Element
Let $G, G'$ be groups. Let $\phi:G\to G'$ be a group homomorphism.
Then prove that for any element $g\in G$, we have
\[\phi(g^{-1})=\phi(g)^{-1}.\]
Definition (Group homomorphism).
A map $\phi:G\to G'$ is called a group homomorphism […]

Normal Subgroups, Isomorphic Quotients, But Not Isomorphic
Let $G$ be a group. Suppose that $H_1, H_2, N_1, N_2$ are all normal subgroup of $G$, $H_1 \lhd N_2$, and $H_2 \lhd N_2$.
Suppose also that $N_1/H_1$ is isomorphic to $N_2/H_2$. Then prove or disprove that $N_1$ is isomorphic to $N_2$.
Proof.
We give a […]

Eckmann–Hilton Argument: Group Operation is a Group Homomorphism
Let $G$ be a group with the identity element $e$ and suppose that we have a group homomorphism $\phi$ from the direct product $G \times G$ to $G$ satisfying
\[\phi(e, g)=g \text{ and } \phi(g, e)=g, \tag{*}\]
for any $g\in G$.
Let $\mu: G\times G \to G$ be a map defined […]

Equivalent Definitions of Characteristic Subgroups. Center is Characteristic.
Let $H$ be a subgroup of a group $G$. We call $H$ characteristic in $G$ if for any automorphism $\sigma\in \Aut(G)$ of $G$, we have $\sigma(H)=H$.
(a) Prove that if $\sigma(H) \subset H$ for all $\sigma \in \Aut(G)$, then $H$ is characteristic in $G$.
(b) Prove that the center […]