The Senate confirmed Rep. John Ratcliffe (R-Tex.) as the next director of national intelligence on Thursday, capping an unusually protracted process in which the congressman withdrew his nomination last year in the face of bipartisan opposition only to have President Trump challenge members of his own party and nominate Ratcliffe again seven months later.

The Senate voted 49-to-44 to confirm Ratcliffe along party lines. He received more votes against his confirmation than any DNI in the 15-year history of the office.

Ratcliffe will assume leadership of a sprawling federation of 17 intelligence agencies, with a collective budget of at least $60 billion, at an acutely vulnerable moment for U.S. national security. Still in the throes of a pandemic that has killed more than 90,000 people in the U.S. and wrought economic devastation, the U.S. is facing a dramatic escalation in tensions with China, the source of the viral outbreak; the prospect of repeated Russian interference in the 2020 election, which the intelligence community Ratcliffe will lead has said is all but certain; and painful decisions about how to support security and defense budgets when the government is spending trillions of dollars to keep the economy from collapsing.

When Trump first tapped Ratcliffe for the post last July, Democrats and Republicans alike were cool to the choice. Ratcliffe had never worked in the intelligence community. And his connections to national security more broadly proved both tenuous — a few years as a federal prosecutor — and exaggerated.

To bolster his nomination, Ratcliffe pointed to his service, beginning in 2004, as the chief of anti-terrorism and national security in the Eastern District of Texas, a position created after the Sept. 11, 2001, attacks in a jurisdiction that didn’t see a high volume of terrorism cases. President George W. Bush later appointed Ratcliffe as the interim U.S. attorney.

But former colleagues and records showed that Ratcliffe didn’t play a significant role in any terrorism cases, contrary to his public claims. In a news release, Ratcliffe had touted his “special appointment as the prosecutor” in a high-profile terrorism financing case in 2008, U.S. v. Holy Land Foundation. But a spokesperson later acknowledged that Ratcliffe’s assignment wasn’t to prosecute the case but rather “to investigate issues related to” why an initial prosecution of Holy Land Foundation resulted in a mistrial.

Ratcliffe also distorted his record on immigration enforcement, a key policy priority of the Trump administration, boasting during his campaign and on his congressional website that he “arrested 300 illegal immigrants in a single day.” That wasn’t true.

Trump’s desire to put Ratcliffe in charge of all U.S. intelligence agencies, which he announced in a tweet, came as a surprise even to White House aides, who had not vetted the three-term congressman and thought the president favored him for a different position, possibly homeland security secretary, officials said at the time.

Trump had been eager to replace former senator Daniel R. Coats as the DNI. The two had a rocky relationship, and Trump was furious at Coats for subtly but unmistakably criticizing the president’s credulous approach to Russia’s leader, Vladimir Putin, particularly on the facts of the Kremlin’s interference in the 2016 election. Trump had long expressed doubts about Russia’s actions, but Coats made clear, on more than one occasion, that the entire intelligence community spoke with a single voice when it assessed that Russia did interfere, and with the goal of helping Trump’s campaign.

Coats resigned on July 28.

Trump thought Republican lawmakers would be pleased when he quickly picked Ratcliffe to replace Coats, officials said at the time. The congressman had been a strident critic of special counsel Robert S. Mueller III’s investigation into Russian interference, which Trump derided as a partisan “hoax” designed to undermine his presidency and aid Democrats.

But key Republicans quickly signaled that Ratcliffe lacked the national security expertise that is required by law to serve as DNI. And the congressman’s colleagues described him as one of the least involved members of the House Intelligence Committee, one of two bodies that conducts oversight of the intelligence community and is routinely briefed on classified matters.

Ratcliffe, who had served on the committee for only seven months, hadn’t traveled overseas to get an up-close view of intelligence operations, as committee members typically do, particularly when they are new to the subject.

Even by the tumultuous standards of the Trump administration, Ratcliffe’s nomination, which fell apart in less than a week, was a spectacular flameout.

Ratcliffe withdrew his nomination on Aug. 2, saying he remained convinced that if confirmed by the Senate he would have served “with the objectivity, fairness and integrity that our intelligence agencies need and deserve.”

In tweets, Trump blamed the media for Ratcliffe’s decision, saying he had been treated “very unfairly.”

“Rather than going through months of slander and libel, I explained to John how miserable it would be for him and his family to deal with these people,” Trump wrote. “John has therefore decided to stay in Congress where he has done such an outstanding job representing the people of Texas, and our Country.”

Ratcliffe will now replace Richard Grenell, the U.S. ambassador to Germany, who has served as the acting DNI since February.

Democrats were outraged by Trump’s decision to pick a fierce partisan combatant as his acting intelligence chief. Grenell, a former State Department official and communications executive, had been a Trump confidant and outspoken defender on Twitter, where he frequently sparred with journalists.

Grenell’s critics warned that he was leading a politically motivated purge of the intelligence director’s office, which had received a whistleblower complaint alleging that Trump pressured the government of Ukraine to investigate his political rivals, charges that helped spark Trump’s impeachment.

In April, Trump fired the intelligence community inspector general, Michael Atkinson, who handled the whistleblower complaint.

Concerns that the Trump administration is attempting to use classified intelligence to political ends flared again last week, after Grenell gave Attorney General William P. Barr a list he had declassified of former Obama administration officials, including then-Vice President Joe Biden, Trump’s presumptive opponent for November’s election, who may have received intelligence documents identifying former national security adviser Michael T. Flynn.

With some lawmakers fearing political interference by the nation’s top intelligence official, congressional aides said Trump presented the Senate with two unpalatable choices when he nominated Ratcliffe a second time: Stick with Grenell, who publicly devoted more attention to attacking his and the president’s opponents than speaking about national intelligence, or accept Ratcliffe, who would not be the most experienced DNI but would, as a confirmed official, be more accountable to Congress.

Earlier this month, in an extraordinary confirmation hearing in which Ratcliffe and members of the Senate Intelligence Committee sat far apart from each other to avoid potential spread of the coronavirus, the nominee faced repeated questioning about whether he would stand up to Trump and if he agreed with the president’s stated belief that a rogue “deep state” of career government officials is trying to undermine his administration.

Several senators, including Susan Collins (R-Maine), whose support was key to Ratcliffe’s confirmation, pressed him on whether he agreed with Trump’s statement last year that the intelligence community had “run amok” and needed to be “rein[ed] in.” After initially not answering the question, Ratcliffe conceded that he did not agree. However, when pressed repeatedly by Sen. Michael F. Bennet (D-Colo.) if he would publicly disavow such a claim by the president, he did not commit, saying only: “I don’t think the men and women of the intelligence agencies are running amok.”

Sen. Dianne Feinstein (D-Calif.), a former committee chairwoman, pressed Ratcliffe on his previous accusations that the intelligence community employee who filed the whistleblower complaint about Trump and Ukraine “made false statements” and “didn’t tell the truth.”

Ratcliffe, who was one of Trump’s most reliable defenders during impeachment hearings, said he didn’t want to “re-litigate” the issues and that he had been concerned Trump didn’t receive “due process” before the House of Representatives.

“I want to make it very clear, if confirmed as DNI, every whistleblower, past, present and future, will enjoy every protection under the law,” Ratcliffe told senators.

Whatever his past statements and actions as a partisan, elected legislator, Ratcliffe said he understood that being the intelligence director demanded he hold no allegiances to party or politics.

“Regardless of what anyone wants our intelligence to reflect, the intelligence I will provide if confirmed will not be altered or impacted by outside influence,” Ratcliffe said.

Paul Kane contributed to this report.