Atom interferometry has proven both a powerful means for probing fundamental physics, and a promising technology for high-precision inertial sensing. However, their performance has been limited by the available interrogation time of atoms falling freely in Earth's gravitational field. Trapped geometries have thus been explored as a means to improve the sensitivity of atom interferometers, but attempts to date have suffered from decoherence caused by trap inhomogeneities. We have demonstrated a trapped atom interferometer with an unprecedented interrogation time of 20 seconds,1 achieved by trapping the interferometer in the resonant mode of an optical cavity. The cavity is instrumental to this advance, as it provides spatial mode filtering for the trapping potential. Because the interferometer is held with the arms vertically separated along the gravitational axis, a phase shift accumulates due to the gravitational potential energy difference between the arms. Moreover, this phase accumulates continuously during the hold time, providing an orders-of-magnitude greater immunity to vibrations than previous atom-interferometric gravimeters at the same sensitivity.