Exotic phenomena in systems with strongly correlated electrons emerge from the interplay between spin and motional degrees of freedom. For example, doping an antiferromagnet is expected to give rise to pseudogap states and high-temperature superconductors. Quantum simulation using ultracold fermions in optical lattices could help to answer open questions about the doped Hubbard Hamiltonian, and has recently been advanced by quantum gas microscopy. Here we report the realization of an antiferromagnet in a repulsively interacting Fermi gas on a two-dimensional square lattice of about 80 sites at a temperature of 0.25 times the tunnelling energy. The antiferromagnetic long-range order manifests through the divergence of the correlation length, which reaches the size of the system, the development of a peak in the spin structure factor and a staggered magnetization that is close to the ground-state value. We hole-dope the system away from half-filling, towards a regime in which complex many-body states are expected, and find that strong magnetic correlations persist at the antiferromagnetic ordering vector up to dopings of about 15 per cent. In this regime, numerical simulations are challenging and so experiments provide a valuable benchmark. Our results demonstrate that microscopy of cold atoms in optical lattices can help us to understand the low-temperature Fermi-Hubbard model.