Jeff Sessions, the president's earliest and most fervent supporter in Congress, stepped down as attorney general Wednesday after brutal criticism from the president, bringing an abrupt end to his controversial tenure as the nation's top law enforcement officer.

President Trump wrote on Twitter after a marathon press conference at the White House that Sessions was out and that Sessions' chief of staff, Matthew Whitaker, would serve as an acting replacement.

Sessions, 71, lasted not quite two years in the job. But in that brief period, the former Alabama senator managed to usher in a new era at the Justice Department.

Sessions threatened so-called sanctuary cities with the loss of federal funding and announced a "zero tolerance policy" for people who cross the southern U.S. border illegally.

He decried a looming wave of violent crime across the country, even though criminologists maintain murders and assaults remain near historic lows in most places.

He ordered federal prosecutors to seek the most serious charges and stiff prison sentences against drug criminals, a stark reversal of former President Barack Obama's most prominent and bipartisan justice policy.

He presided over a rollback in investigations of local police. He rescinded policies that directed federal prosecutors to go after only the biggest cases involving marijuana in states where the drug is legal. And he recommitted to using private prisons for U.S. inmates and detainees.

A long fuse

The seeds of Sessions' departure were planted, ironically, during his confirmation hearing. Sessions went out of his way to deny meeting with Russians in the course of the 2016 presidential campaign. His former colleagues in the Senate approved the nomination 52 to 47, despite concerns about allegations of racial insensitivity and hostility to civil rights in his past.

But Sessions soon ran into trouble.

He was forced to correct his Senate testimony, to indicate he had, in fact, met with the Russian ambassador at least twice in 2016. Democrats on Capitol Hill accused him of making false statements. The disclosure provoked intense public scrutiny of his actions.

By March of 2017, Sessions fielded questions almost daily about whether he could oversee the ongoing Department of Justice investigation into Russian interference in the election, given his vocal role in the campaign, in which he even donned a "Make America Great Again" hat to support Donald Trump.

Ultimately, after consulting with DOJ ethics officials, Sessions recused himself from the Russia probe. He cited longstanding rules regarding conflicts that arise when authorities investigate campaigns in which they participate.

The recusal decision was hailed by Democrats and good government groups. The president had a different reaction.

Two sources familiar with the situation have told NPR President Trump raged, sometimes profanely, in phone and face-to-face conversations with Sessions. It didn't take long for Trump to voice open regret, on social media an in interviews, about having nominated Sessions.

The president grew even more antagonistic when Sessions' deputy, Rod Rosenstein, appointed a special counsel to lead the Russia investigation after Trump fired FBI Director James Comey.

Trump called the DOJ Russia probe a "witch hunt" and cast aspersions on its leader, former FBI Director Robert Mueller, a registered Republican. Trump's allies produced an ad attacking Mueller's team for donating to Democratic political campaigns.

All the while, Sessions ducked questions on the matter, given his recusal.

But as Mueller hired more than two dozen staff members and prosecutors, with experience in corporate fraud, money laundering, organized crime and executive privilege, Trump exploded. He denigrated Sessions, Rosenstein, Mueller and the entire post-Watergate practice of law enforcement independence from the White House in an interview with the New York Times.

"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.

Former Justice Department veterans said those remarks reflected a deep misunderstanding of the culture at the Justice Department and the FBI — which try to insulate their work from politics — and a sense that Trump was acknowledging he wanted his attorney general to protect him in the Russia investigation, not get to the bottom of the matter.

The issue gnawed at Trump, who days later issued a series of early morning tweets on July 22, 2017, wondering why Democrat Hillary Clinton and Comey were not under investigation for unspecified offenses. He repeated the question on July 24, 2017, referring to Sessions as "our beleaguered A.G."

The political establishment in Washington, D.C., began wondering aloud how long Sessions could keep his job. At first, former colleagues in the Senate mobilized and came to his aid, defending his integrity.

Sen. Lindsey Graham, R-S.C., told reporters, "If Jeff Sessions is fired, there will be holy hell to pay." Sen. Chuck Grassley, R-Iowa, who leads the Senate Judiciary Committee, tweeted "no way" would he hold confirmation hearings for a new attorney general in 2017.

For his part, Sessions told Tucker Carlson of Fox News that the barbs from Trump had been "hurtful" but that he served at the pleasure of the president.

Attorney general of everything else

Sessions kept working. He flew to El Salvador for a series of anti-gang meetings in late July 2017. There, the attorney general told graduates of a law enforcement academy that he was "blessed" to serve as the highest justice official in the United States.

"It is an honor I never expected nor one I ever would have thought possible," Sessions said. "And while there are good days and bad days in any job, one thing has been clear to me, it is a privilege to serve one's country in law enforcement to wake up each morning and fight the fight for the rule of law."

And Sessions continued to set the broad priorities of the Justice Department, including a crackdown on illegal immigration and support for cases of religious liberty — although those priorities sometimes came into conflict.

His boss, Trump, appeared to have less respect for the legal system. After the special counsel unsealed indictments against his onetime campaign chairman, Paul Manafort, and Manafort deputy Richard Gates on Oct. 30, 2017, Trump insisted there was "no collusion" with Russia and reiterated his view that the investigation was a waste of time.

In early November 2017, Trump told reporters, "a lot of people are disappointed in the Justice Department, including me." He said he was "frustrated" he could not direct DOJ or the FBI to take action in specific cases, remarks that Justice Department veterans consider a serious breach.

At the same time, questions about Sessions' conduct during the campaign resurfaced after a guilty plea by onetime foreign policy aide George Papadopoulos.

Papadopoulos told prosecutors that he tried to set up a meeting between Trump and Russian President Vladimir Putin during the campaign, and that he mentioned it at a March 2016 meeting attended by both Trump and Sessions.

"These facts appear to contradict your sworn testimony on several occasions," Democrats on the House Judiciary Committee pointed out in a letter to the attorney general.

Sessions would get another chance on Capitol Hill to explain what he did in 2016 and how it related to Russia. In essence, he argued, he had a memory lapse, and recent news accounts of the Papadopoulos plea refreshed his recollection.

"I have always told the truth, and I have answered every question as I understood them and to the best of my recollection," the attorney general told lawmakers at a hearing on Nov. 14, 2017. "But I will not accept and reject accusations that I have ever lied under oath. That is a lie."

Sessions's lawyer confirmed that in early 2018, the attorney general voluntarily sat for an extended interview with special counsel investigators, as a witness in the probe into possible obstruction of justice by the president.

Trump later said he was "not concerned" about that interview.

To the dismay of former Justice Department leaders, Sessions mostly remained silent in late 2017 as the president attacked the DOJ as a "Deep State" and tweeted the FBI's reputation was "in Tatters."

And, though he seemed to take action by reportedly directing federal prosecutors and FBI agents to look into Trump's political opponent Hillary Clinton, her email practices and the Clinton Foundation, that wasn't enough for conservative members of his own party.

Two members of the House Freedom Caucus wrotein early 2018 that "it would appear [Sessions] has no control at all of the premier law enforcement agency in the world."

The two conservative House Republicans also suggested even then that it was time for Sessions to go.

Time marches on

Still, the Justice Department moved ahead.

Following the guilty plea by Trump lawyer and fixer Michael Cohen, and the conviction of the president's former campaign chairman, Paul Manafort on the same day in August, Trump lashed out at Sessions, telling Fox News that the attorney general had never taken control of the Justice Department.

The president added that Sessions only had the plum job because of Sessions's loyalty during the campaign. But in a rare defense of himself and his department, Sessions issued a public statement.

"I took control of the Department of Justice the day I was sworn in, which is why we have had unprecedented success at effectuating the President's agenda—one that protects the safety and security and rights of the American people, reduces violent crime, enforces our immigration laws, promotes economic growth, and advances religious liberty," Sessions said.

So long as he was attorney general, Sessions added, the Justice Department "will not be improperly influenced by political considerations."

Sessions said he was proud of law enforcement officials and agents, whom he described as the best in the world.

Copyright 2018 NPR. To see more, visit http://www.npr.org/.