The nearby radio galaxy M87 offers a unique opportunity to explore the connections between the central supermassive black hole and relativistic jets. Previous studies of the inner region of M87 revealed a wide opening angle for the jet originating near the black hole. The Event Horizon Telescope resolved the central radio source and found an asymmetric ring structure consistent with expectations from General Relativity. With a baseline of 17 years of observations, there was a shift in the jet's transverse position, possibly arising from an eight to ten-year quasi-periodicity. However, the origin of this sideways shift remains unclear. Here we report an analysis of radio observations over 22 years that suggests a period of about 11 years in the position angle variation of the jet. We infer that we are seeing a spinning black hole that induces the Lense-Thirring precession of a misaligned accretion disk. Similar jet precession may commonly occur in other active galactic nuclei but has been challenging to detect owing to the small magnitude and long period of the variation.