David Axelrod, who served as Obama’s chief strategist and adviser, said in a tweet Wednesday that the former president campaigned for swing-state Democrats when voters were paying attention. Democrats breathed a sigh of relief Wednesday after avoiding the midterm election washout that’s become common for parties in power. Axelrod said Obama helped his party cling to power as he talked up Democratic candidates and ripped their Republican opponents.

Polling throughout the 2022 midterms showed Democrats facing strong political headwinds over inflation and President Joe Biden’s unpopularity. But Obama, who remains popular with Democrats since leaving office in 2017, stumped for candidates in Georgia, Wisconsin, Pennsylvania and Michigan just days before voters cast ballots in key races.

“People asked why@BarackObama waited until the final 10 days of the campaign to emerge,” Axelrod said in the tweet. “But his job was to be the closer, make final arguments and spur turnout when folks were paying attention. Turns out, the timing was just right!”

Appearing in Pittsburgh the Saturday before the election, Obama chided Republican Senate candidate Dr. Mehmet Oz as a “snake oil man,” citing the celebrity physician’s support for health products that experts have viewed skeptically. Obama, who twice carried Pennsylvania, urged voters to back Lieutenant Governor John Fetterman for Senate, who went on to prevail.

In Michigan, Obama rallied for Michigan Governor Gretchen Whitmer, shutting down a heckler while mocking Republican challenger Tudor Dixon, who had roles in zombie films and has trafficked in conspiracy theories.

While Biden has struggled with sagging approval ratings, Obama remains a popular figure. The Pew Research Center released the results of a poll in 2018 finding that more Americans named Obama as the best president of their lifetimes than any other president. A 2021 poll by Pew found that 59 percent of Democrats and Democratic-leaning independents said Obama had been the best president of the last 40 years.

President George W. Bush is the only president in the last 30 years to not lose a chamber of Congress in a midterm election, gaining seats in the 2002 elections.

Democrats lost 63 House seats in the 2010 election, handing control of the House to Republicans in a loss that Obama described as a “shellacking.” Four years later, Obama’s party lost control of the Senate as well.

As ballots continue to be counted in the 2022 midterms, Democrats may have avoided a “red wave” by retaining a narrow path to keeping control of the Senate. Control of the House remains up for grabs, but Republicans are favored to win.

Newsweek has reached out to Obama for comment.