Experiments and computations are presented for a foil pitching about its leading edge near a planar, solid boundary. The foil is examined when it is constrained in space and when it is unconstrained or freely swimming in the cross-stream direction. It was found that the foil has stable equilibrium altitudes: the time-averaged lift is zero at certain altitudes and acts to return the foil to these equilibria. These stable equilibrium altitudes exist for both constrained and freely swimming foils and are independent of the initial conditions of the foil. In all cases, the equilibrium altitudes move farther from the ground when the Strouhal number is increased or the reduced frequency is decreased. Potential flow simulations predict the equilibrium altitudes to within 3 %–11 %, indicating that the equilibrium altitudes are primarily due to inviscid mechanisms. In fact, it is determined that stable equilibrium altitudes arise from an interplay among three time-averaged forces: a negative jet deflection circulatory force, a positive quasistatic circulatory force and a negative added mass force. At equilibrium, the foil exhibits a deflected wake and experiences a thrust enhancement of 4 %–17 % with no penalty in efficiency as compared to a pitching foil far from the ground. These newfound lateral stability characteristics suggest that unsteady ground effect may play a role in the control strategies of near-boundary fish and fish-inspired robots.