I will discuss three former presidents who had significant service in public office after leaving the White House.
The first was John Quincy Adams. He served one term as president (1825-9) and reached the presidency in an odd way. Adams is one of only two presidents who were elected by the House of Representatives, because no candidate received an electoral college majority.
Andrew Jackson led in both popular votes and electoral votes in the 1824 election. However, his electoral votes were only 37.9% of the total. The House, pursuant to the 12th Amendment, voted among the top three candidates, and chose Adams.
The two-party system was in a state of flux at that time, in transition from the earlier Republican/Federalist two-party system, to one involving the Democratic and Whig parties. That's why the electoral vote was splintered in that manner.
Adams was not reelected in 1828. Jackson finally achieved the presidency in that election.
Before he became president, Adams had had a diplomatic career, culminating in his tenure as secretary of state in the Monroe Administration. He also had one term in the U.S. Senate. While his place in history is cemented by his having been president, albeit for only one term, Adams is more respected for his achievements in those other jobs. So, perhaps it's not surprising that he decided to return to non-presidential public service.
In 1830, Adams was elected to the House of Representatives. No other former president has ever done that. His Massachusetts constituents continued to reelect him until he died in office in 1848. In fact, he died in the Capitol building, having been moved to the Speaker's Room after suffering a cerebral hemorrhage in the House chamber. The House website provides this information about Adams's time in the House.
A brief footnote: the only other former president to serve in Congress was Andrew Johnson. The Tennessee legislature elected him to the Senate in 1874, but he served less than five months, before he died on July 31, 1875. The main significance of that is that it briefly returned Johnson to the legislative body that had come within one vote of removing him from the presidency in the impeachment trial of 1868.