A federal judge on Thursday sentenced Roger Stone to 40 months in prison—saying his lies to Congress were a threat to “the very foundation of our democracy,” but still giving him less time than prosecutors had originally recommended.

They had asked for a sentence of seven to nine years, which infuriated President Donald Trump. The Department of Justice then stepped in and suggested a much lower sentence, but Judge Amy Berman Jackson said the self-professed dirty trickster still deserved “substantial” time.

“The truth still exists. The truth still matters,” Jackson said in a speech before handing down the sentence. “Roger Stone’s insistence that it doesn’t—his belligerence, his pride in his own lies—are a threat to our most fundamental institutions, to the very foundation of our democracy.”

Stone—who was convicted last November of seven charges, including lying to congressional investigators, witness tampering, and obstructing justice—won’t immediately go to prison. Jackson is weighing a motion from his lawyers for a retrial. Stone’s team have argued that anti-Trump social media posts from the jury forewoman meant his conviction was tainted by political bias. President Trump has tweeted the same sentiment.

Jackson said Thursday the prosecution was not a political hit job.

“He was not prosecuted, as some have complained, for standing up for the president,” she declared. “He was prosecuted for covering up for the president.”

The judge also noted that Stone lied to Congress when he said he had no written communications with his WikiLeaks intermediary, Jerome Corsi. She said Stone should spend substantial time behind bars because he lied about a matter of national and international importance.

“This is not campaign hijinks,” Jackson said. “This is not Roger just being Roger.”

Stone’s sentencing process became a political near-emergency for the Trump administration. Last week, the career prosecutors handling the case—including three alums of Special Counsel Robert Mueller’s probe—recommended the judge give Stone a sentence of seven to nine years in prison. At about 2 a.m. the morning after the recommendation was filed, Trump tweeted out pointed criticism of the move.

The next morning, unnamed Justice Department officials signaled to reporters that headquarters would overrule the recommendation. And that afternoon, they filed a letter with the court overriding the prosecutors and calling for Stone to receive a much shorter prison sentence. As a result, all four prosecutors handling the Stone case withdrew from it.

Attorney General Bill Barr has maintained that he made up his mind about the sentence before seeing the president’s tweet. But in an eye-popping interview with ABC News, he did say that Trump’s tweets about DOJ cases “make it impossible” for him to do his job.

Jackson said Thursday that “the government’s initial memorandum was thorough, well-researched, and supported”—but that even without the “unprecedented actions” by the DOJ in the past week, she still would think seven to nine years is too long.

Earlier in the hearing, John Crabb, deputy chief of the Criminal Division of the D.C. U.S. Attorney’s office, apologized for the confusion the government created in the sentencing process.

“I fear that you know less about the case and saw less of the testimony and exhibits than just about everybody else in this courtroom, with possible exception of the defense attorney who just joined the team,” Jackson told him.

Crabb replied that “this confusion was not caused by the original trial team.”

“This prosecution was and this prosecution is righteous,” he said, adding that the original trial team had authorization from the U.S. Attorney’s office to file the memo they submitted.

A key substantive issue in the dispute over Stone’s sentence was whether or not the judge should weigh messages between Stone and his ex-associate Randy Credico in determining whether to add several years to the baseline sentence.

In one of the messages, Stone wrote to Credico, “I am so ready. Let’s get it on. Prepare to die.” In another, he wrote, “I’m going to take that dog away from you. Not a fucking thing you can do about it either, because you are a weak, broke, piece of shit.” In recommending the seven-to-nine-year sentence, the prosecutors called those comments “outright threats.”

At the sentencing hearing, defense attorney Seth Ginsberg brushed off the messages, insisting, “Mr. Stone is known for using rough, provocative, hyperbolic language.”

“Mr. Credico knew that. They have a long, 20-year relationship,” he added. “Mr. Credico understood it was just Stone being Stone. He’s all bark, no bite.”

But Jackson repudiated Ginsberg’s assertion, saying the messages were “hardly” just banter, as the defense had claimed.

“Mr. Credico, who had no wife or children, was extremely close to his dog of 12 years and Mr. Stone knew that well,” Jackson said. “This is intolerable to the administration of justice and the court should not sit idly by, shrug its shoulders, and say, ‘Oh, that’s just Roger being Roger,’ or it wouldn’t have grounds to act the next time someone tries it.”

Credico wrote in a letter to the judge that he never believed Stone posed “a direct physical threat” to him or to his small fluffy dog, Bianca—and the DOJ cited the letter in its decision to override the prosecutors’ initial recommendation.

But Jackson called the letter into question on Thursday, saying Credico “appeared on the stand to be a highly nervous individual, and it may well be even today that he just doesn’t want to be known as the reason behind a tough sentence.”

Credico told The Daily Beast on Wednesday he was angry that Justice Department leadership used his letter to push for a shorter sentence.

“These are the type of guys that any defense attorney would want as a prosecutor, because they did not cheat, they did not fudge, they just did their job and methodically went through with it,” he said of the original team. “So for Trump to give these guys a bum rap and then Barr gave them the bum’s rush—these guys are two fucking bums to do that, because you are besmirching and smearing four career civil servants.”

Stone’s involvement in the Trump/Russia saga goes way back. Stone says Roy Cohn introduced him to Trump in 1979, as The Wall Street Journal has detailed. Stone’s lobbying firm later did work for the Trump organization, and the men attended each other’s weddings (in Stone’s case, he attended two of Trump’s, per WSJ). Stone also joined Trump’s then-longshot 2016 presidential bid right at its inception, but soon left the operation. Trump has said he fired Stone, while Stone says he quit.

Regardless, Stone continued to be an enthusiastic Trump booster even after parting ways with the campaign, and campaign staffers viewed Stone as a backchannel to Wikileaks, according to testimony in his trial.

“The campaign had no official access to WikiLeaks or to Julian Assange,” ex-White House adviser Steve Bannon testified. “But Roger would be considered if we needed an access point, because he had implied or told me he had a relationship with WikiLeaks and Julian Assange.”

And Rick Gates, who worked on Trump’s campaign with Bannon, testified that Trump himself discussed Wikileaks with Stone in the summer of 2016.

Stone claimed to congressional investigators that Credico was his back channel to Wikileaks. But Credico has denied filling any such role, and prosecutors said Stone lied to protect another potential go-between: conspiracy theorist Jerome Corsi. According to an email, Stone asked Corsi to make contact with the hacker group. Corsi appeared to indicate in response to Stone that he had somehow succeeded.

“Word is friend in embassy plans 2 more dumps,” he emailed Stone, predicting email releases in August and October 2016. “Impact planned to be very damaging.”

The impact was damaging. Just hours after news broke of the Access Hollywood tape, Wikileaks started releasing emails stolen from Hillary Clinton’s campaign chairman, John Podesta. Those emails included a trove of details on Clinton World and pushed the campaign into a tailspin just weeks before the election.