By Maggie Haberman, Julian E. Barnes and Peter Baker, New York Times–

President Trump announced on Sunday that Dan Coats would step down as the director of national intelligence after a fraught tenure marked by tension with the Oval Office, and he tapped one of his staunch defenders, Representative John Ratcliffe, to take over the country’s expansive network of spy agencies.

Mr. Coats, a former senator and longtime pillar of the Republican establishment who angered the president by providing unwelcome assessments of Russia, North Korea and other matters, told Mr. Trump last week that it was time to move on, officials said. His departure removes one of the most prominent national security officials willing to contradict the president.

If Mr. Ratcliffe is confirmed by the Senate, he will offer a starkly different perspective in the Situation Room, one more in line with Mr. Trump’s thinking. Mr. Ratcliffe, a third-term Republican from Texas and a former prosecutor, has embraced Mr. Trump’s theories about the Russia investigation and was among the sharpest questioners of Robert S. Mueller III, the former special counsel, at last week’s hearings.

Mr. Trump met with Mr. Ratcliffe on July 19 to discuss the job, but the hearings just five days later offered the congressman a chance to essentially audition for the president, who enjoyed watching him grill Mr. Mueller, according to people informed about the process.

Some Republicans, however, privately expressed concern, including Senator Richard M. Burr of North Carolina, the chairman of the Senate Intelligence Committee, who cautioned the president’s advisers that he considered Mr. Ratcliffe too political for the post, according to people familiar with the discussions. Mr. Trump disregarded the warning.

“I am pleased to announce that highly respected Congressman John Ratcliffe of Texas will be nominated by me to be the Director of National Intelligence,” Mr. Trump wrote on Twitter after reports in Axios and The New York Times about the personnel change. “A former U.S. Attorney, John will lead and inspire greatness for the Country he loves.”

The president offered appreciation but scant praise for Mr. Coats. “I would like to thank Dan for his great service to our Country,” Mr. Trump wrote without elaboration.

Mr. Burr made no comment about Mr. Ratcliffe, a telling decision for the Republican whose committee will consider his confirmation. Senator Mark Warner of Virginia, his Democratic vice chairman, likewise did not mention Mr. Ratcliffe, but offered pointed praise for Mr. Coats.

“The mission of the intelligence community is to speak truth to power,” Mr. Warner said in a statement. “As D.N.I., Dan Coats stayed true to that mission.”

Senator Chuck Schumer of New York, the Democratic leader, did not hold back, saying that Mr. Ratcliffe was clearly “selected because he exhibited blind loyalty to President Trump with his demagogic questioning” of Mr. Mueller and that his confirmation “would be a big mistake.”

Mr. Coats, 76, who represented Indiana in the House and the Senate for 24 years and served as ambassador to Germany under President George W. Bush, had been an important link between Mr. Trump and the Republican establishment. Without Mr. Coats or figures like Jim Mattis, Mr. Trump’s first defense secretary, and Nikki R. Haley, the former ambassador to the United Nations, the president is increasingly surrounded by loyalists.

Rep. John Ratcliffe wearing a suit and tie: Representative John Ratcliffe, Republican of Texas, was among the sharpest questioners of Robert S. Mueller III, the former special counsel, at last week’s hearings.© Doug Mills/The New York Times Representative John Ratcliffe, Republican of Texas, was among the sharpest questioners of Robert S. Mueller III, the former special counsel, at last week’s hearings.

Indeed, Mr. Trump’s grip on the party has only strengthened, demonstrating that the establishment needs his support far more than he needs its. To Mr. Trump, Mr. Coats had come to represent the disapproving Republican elite that he scorned, and his frustration with his intelligence director spiked again during spring weekends at his club in Florida, according to people who spoke with him then.

Mr. Coats had long been expected to depart of his own accord, an administration official said, but remained to avoid appearing to be forced out. The president asked him in February to stay longer, but in a meeting last week with Mr. Trump and Vice President Mike Pence, Mr. Coats said he was ready to leave. Mr. Coats finished his resignation letter a week ago and submitted it on Sunday, effective Aug. 15, according to a person familiar with its drafting.

[Read Mr. Coats’s resignation letter.]

“The intelligence community is stronger than ever and increasingly well prepared to meet new challenges and opportunities,” Mr. Coats wrote in the letter, citing among other accomplishments his appointment of a top executive charged with forestalling future election interference.

“It’ll be a big loss for the intelligence community, and, for that matter, the nation,” said James R. Clapper Jr., who served as intelligence director under President Barack Obama. “Dan has been pretty courageous about speaking truth to power over his entire tenure.”

From the start, Mr. Coats maintained independence from Mr. Trump. He was vocal in defending intelligence agencies and their assessment that Russia interfered in the 2016 election on Mr. Trump’s behalf, and he emphasized those findings leading up to the president’s meeting with President Vladimir V. Putin of Russia in Helsinki, Finland, in 2018.

At a security conference in Aspen, Colo., soon afterward, Mr. Coats expressed surpriseabout reports that Mr. Trump could invite Mr. Putin to the White House. “That is going to be special,” he said sarcastically in a notably unguarded moment.

Aides to Mr. Trump seized upon that to suggest Mr. Coats was disloyal and should be fired. But he was shielded by Mr. Pence, a longtime protégé and former governor of Indiana.

After Aspen, Mr. Coats adopted a lower profile, but he tried to protect national security officers from the president’s criticism and took the lead in a Jan. 29 presentation of global threats that was at odds with Mr. Trump’s views.

In the report and testimony before the Senate, Mr. Coats said that North Korea was unlikely to give up its nuclear stockpile, that Iran was not immediately taking steps to build a nuclear weapon and that the Islamic State was still capable of stoking violence in Syria — all facts that undermined Mr. Trump’s assumptions.

The next day, the president called his intelligence chiefs “passive and naïve.” In an indignant Twitter post, Mr. Trump wrote, “Perhaps Intelligence should go back to school!”

In a speech to intelligence officers in January, Mr. Coats said it was their duty to seek the truth about the world. “And when we find that truth, to speak the truth,” he added.

In recent months, Mr. Coats discovered that it was difficult to align himself with the president — particularly on Russia. Mr. Coats saw Russia as an adversary and pushed for closer cooperation with American allies in Europe. Time after time, the White House sought to weaken Mr. Coats’s language regarding the Kremlin.

A secret report by Mr. Coats about interference in the 2018 midterm elections contained a harsh assessment about Russia’s efforts to influence the American public by stoking conspiracy theories and polarization. But the public statement, edited by the White House, contained little of the tough language.

Mr. Ratcliffe, on the other hand, cast Russia’s role in a different light during last week’s hearings, adopting the president’s claim that it was actually Hillary Clinton’s campaign that colluded with Moscow through a dossier of unverified claims about Mr. Trump compiled by Christopher Steele, a former British intelligence officer.

“I very much agree with your determination that Russia’s efforts were sweeping and systematic,” Mr. Ratcliffe told Mr. Mueller. “I think it should concern every American. That’s why I want to know just how sweeping and systematic those efforts were. I want to find out if Russia interfered with our election by providing false information through sources to Christopher Steele about a Trump conspiracy that you determined didn’t exist.”

Mr. Ratcliffe also hammered Mr. Mueller for saying he could not exonerate Mr. Trump on obstruction of justice, declaring that such a determination was beyond his mission.

“I agree with the chairman this morning when he said Donald Trump is not above the law,” Mr. Ratcliffe said. “He’s not. But he damn sure shouldn’t be below the law.”

Critics disagreed, noting that Justice Department guidelines call for a special counsel to provide a report “explaining the prosecution or declination decisions” at the end of an investigation.

But his performance earned him attention among conservatives as well as an invitation to appear on Fox News on Sunday before the president’s announcement. In that appearance, Mr. Ratcliffe suggested that Mr. Mueller’s halting testimony in which he sometimes seemed to struggle to keep up meant he was not really in charge of the investigation.

“The Mueller report and its conclusions weren’t from Robert Mueller,” Mr. Ratcliffe said. “They were written by what a lot of people believe was Hillary Clinton’s de facto legal team, people that had supported her, even represented some of her aides.”

Mr. Ratcliffe, 53, served as the mayor of Heath, Tex., and as a United States attorney, bragging on his website that he once “arrested 300 illegal aliens in a single day.” He was elected to the House in 2014, ousting Representative Ralph Hall in a Republican primary and quickly established a reputation as a stalwart on the right. In 2016, he boasted of being rated the second most conservative member of Congress by Heritage Action for America.

Mr. Ratcliffe’s name has been floated for attorney general, a job he evidently prefers to the intelligence post, but one unlikely to be available anytime soon.

Whatever misgivings he previously voiced, Mr. Ratcliffe told allies in recent days that he was excited about replacing Mr. Coats. And while the Mueller hearings may have influenced Mr. Trump, Mr. Ratcliffe was voicing views of the investigation that he truly believes, people close to him said.

Mr. Ratcliffe comes with significant advantages: He has served on the House Intelligence Committee and worked on counterterrorism initiatives. He is viewed as smart by Republicans who have worked with him, and he has a previous relationship with Christopher A. Wray, the F.B.I. director, from their time serving in the Bush administration.

But he had little intelligence background before arriving in Congress even though the law requires “extensive national security expertise” for the position, and intelligence veterans expressed alarm at what they worry was the politicization of the position.

“The ability to tell truth to power was the traditional qualification for the director of national intelligence,” said Dennis R. Blair, another former director under Mr. Obama. “More recently, sucking up to power seems to be what is expected.”

Douglas Wise, a former C.I.A. officer and deputy head of the Defense Intelligence Agency, said the appointment could pose an “existential threat” to the agencies. “Intelligence has to be candid, truthful and accurate even if it is unpleasant and does not confirm to the biases of the president,” he said.

Senator Angus King, a Maine independent who caucuses with Democrats, would not comment on Mr. Ratcliffe but said the job was to present unvarnished facts.

“We have gotten in trouble in this country in the past when we have cherry-picked intelligence for political purposes or to suit the needs of the president,” he said. “That is the worst thing that can happen.”

Eric Schmitt and Nicholas Fandos contributed reporting.