Conjecture. Let $G$ and $H$ denote groups, and let $f : G \rightarrow H$ denote a function. Then $f$ is a homomorphism precisely when the graph of $f$ is a subgroup of the direct product $G \times H$.
Motivation. It has been proven elsewhere that if we replace the instances of the word "groups" with the word "vector spaces", and if we replace "homomorphism" with "linear map," and "subgroup" with "linear subspace" then the conjecture is true. (However, that proof is not in English.)
Is this a well-known result? Can anyone think of a counterexample?