Using the Monte Carlo method of statistical physics, we compute the equilibrium statistical mechanics of the shallow water equations, considered as a reduced-gravity model of the ocean's upper layer in a square ocean that spans the equator. The ensemble-averaged flow comprises a westward drift at low latitudes, associated with the poleward deepening of the main thermocline, and a more intense compensating eastward flow near the latitudes at which the layer depth vanishes. Inviscid numerical simulations with a model that exactly conserves mass, energy, and potential enstrophy support the theoretical prediction.