If there was any question why Attorney General Jeff Sessions—a respected Alabama senator for 20 years—allowed himself to be turned into the president’s doormat this summer, the answer appeared to come in September.

That was when Sessions announced that the administration would end Deferred Action for Childhood Arrivals, or DACA, a program dating to the administration of Barack Obama, which had granted temporary legal status to some 800,000 young immigrants illegally brought to the U.S. as children.

It was a victory for a man who, as a senator, had often stood out as an immigration hardliner, and as attorney general, had recently endured withering public and private attacks from a president whom he was among the first on Capitol Hill to endorse.

After years in which he and others castigated DACA for circumventing the nation’s legal immigration system, Sessions got to sound its death knell. 

And while his tone when he delivered his remarks was serious, a New York Times photographer caught him smiling offstage, just before taking the podium.

It was a win for President Donald Trump as well: By having Sessions announce the end of DACA, Trump distanced himself from the political fallout of ending a program that’s generally popular on both the left and the right.

Just two months earlier, Trump had lambasted Sessions during an interview with The New York Times, lacing into his attorney general for deciding to recuse himself from the Justice Department’s investigation into Russian interference in the 2016 election, an inquiry that may also be examining potential collusion between the Kremlin and members of the Trump campaign team.

“Sessions should have never recused himself, and if he was going to recuse himself, he should have told me before he took the job, and I would have picked somebody else,” Trump said.

Through the next two weeks, the president continued to treat his attorney general like a punching bag. On Twitter, he questioned why Sessions didn’t replace a top FBI official who had helped oversee the investigation into former Secretary of State Hillary Clinton’s use of a private email server, appeared to blame the attorney general for supposed “illegal leaks” to news outlets, and harangued Sessions for supposedly taking “a VERY weak position on Hillary Clinton crimes.”

The attacks behind closed doors were reportedly even worse: In May, President Trump “berated” Sessions in an Oval Office meeting, accusing him of “disloyalty” as he “unleashed a string of insults on his attorney general” after learning that the Justice Department was appointing a special counsel to oversee the investigation into Russian interference in the 2016 election, according to The New York Times.

Sessions reportedly said he would resign, an offer Trump ultimately refused to accept. The attacks would resume two months later.

Throughout, the attorney general publicly maintained that he still enjoyed the “honor of serving as attorney general,” and that he intended “to continue to do so as long as that is appropriate.” His strongest response to the president’s remarks was that they were “hurtful.”

Springing to Sessions’ defense were hardline immigration groups and Sessions’ former Republican colleagues in the Senate, who saw Sessions as an instrumental part of carrying out conservative priorities. 

Sessions, meanwhile, appeared to attempt to win his way back into Trump’s affections. In addressing the president’s remarks, Sessions called Trump a “strong” leader, and he announced in early August—barely a week after the Twitter attacks—that leak investigations by the Justice Department had tripled under the new administration.

Trump eventually focused on other targets—from the NFL and its players to Clinton and the news media. The attorney general, meanwhile, has taken steps to reinstitute tough prison sentences and reinvigorate the war on drugs, crack down on so-called sanctuary cities that do not fully comply with federal immigration enforcement, and reduce federal oversight of local police departments.

In the end, the president’s anger over the Russia investigation and Sessions’ recusal has not prevented the attorney general from carrying out the work he’d spent two decades trying to accomplish in Congress. And for Sessions, achieving his agenda may be worth a little public humiliation.