Manipulation of spin states at the single-atom scale underlies spin-based quantum information processing and spintronic devices. These applications require protection of the spin states against quantum decoherence due to interactions with the environment. While a single spin is easily disrupted, a coupled-spin system can resist decoherence by using a subspace of states that is immune to magnetic field fluctuations. Here, we engineered the magnetic interactions between the electron spins of two spin-1/2 atoms to create a “clock transition” and thus enhance their spin coherence. To construct and electrically access the desired spin structures, we use atom manipulation combined with electron spin resonance (ESR) in a scanning tunneling microscope. We show that a two-level system composed of a singlet state and a triplet state is insensitive to local and global magnetic field noise, resulting in much longer spin coherence times compared with individual atoms. Moreover, the spin decoherence resulting from the interaction with tunneling electrons is markedly reduced by a homodyne readout of ESR. These results demonstrate that atomically precise spin structures can be designed and assembled to yield enhanced quantum coherence.