When Gov. Ron DeSantis of Florida announced last summer that he had taken the extraordinary step of removing a local prosecutor from his job, he cast his decision as a bold move to protect Floridians.

The prosecutor, Andrew H. Warren, a twice-elected state attorney for Hillsborough County and a Democrat, had signed a public pledge not to prosecute those who seek or provide abortions. Moreover, he was among a group of progressive prosecutors around the country who, in Mr. DeSantis’s words, think “they get to pick and choose which laws that they are enforcing,” the governor told reporters and handpicked supporters at a news conference.

Those left-leaning prosecutors, he said, had “undermined public safety” and been “devastating to the rule of law.”

Left unsaid, however, was that Mr. DeSantis and his advisers had failed to find a connection between Mr. Warren’s policies and public safety in his community.

In fact, just the day before, writing in blue pen on a draft of an executive order, the governor had personally removed any mention of crime statistics justifying Mr. Warren’s suspension, after Mr. DeSantis’s lawyers lamented that they could find nothing in them to support the idea that Mr. Warren’s policies had done harm, according to internal documents and testimony.

As he travels the country promoting a new book and his expected presidential campaign, Mr. DeSantis repeatedly points to his ouster of Mr. Warren as an example of the muscular and decisive way he has transformed Florida — and could transform the nation. He casts Mr. Warren as a rogue ideologue whose refusal to enforce the law demanded action.

But a close examination of the episode, including interviews, emails, text messages and thousands of pages of government records, trial testimony, depositions and other court records, reveals a sharply different picture: a governor’s office that seemed driven by a preconceived political narrative, bent on a predetermined outcome, content with a flimsy investigation and focused on maximizing media attention for Mr. DeSantis.

Two weeks after his removal, Mr. Warren sued the governor in federal court seeking his reinstatement. The lawsuit, which Mr. Warren appealed after it was dismissed in January, produced a significant quantity of discovery, which The New York Times reviewed in detail.

Months before suspending Mr. Warren, Mr. DeSantis had ordered his staff to find progressive prosecutors who were letting criminals walk free. Under oath, his aides later acknowledged that they had deliberately avoided investigating Mr. Warren too closely, so that they would not tip him off and prompt him to reverse his policies — thwarting the goal of making an example of him. When contrary information did materialize, Mr. DeSantis and his lawyers dismissed or ignored it, the records show.

Only after Mr. Warren was removed did the governor’s aides seek records from Mr. Warren’s office that might help justify Mr. DeSantis’s action.

If the investigation into Mr. Warren was cursory at best, the preparation to remove him while simultaneously publicizing that ouster involved greater planning. And those plans were executed with military precision. The governor’s aides gave special attention to news outlets they referred to as “friendly.” Immediately after the news conference, DeSantis aides exerted influence over communications at the state attorney’s office, an independent county agency, working to ensure that the takeover did not result in negative coverage.

And that night, the governor headlined Fox News’s “Tucker Carlson Tonight” to promote his move. Mr. Carlson opened with a 12-minute speech about prosecutors who disregard the law, then turned to an exclusive interview with the governor.

“Ron DeSantis is the man who put an end to it today in the state of Florida,” Mr. Carlson said.

Although Mr. DeSantis’s move was cheered in the conservative news media as a victory in his war on “wokeness,” a federal judge ruled in January that the governor had violated Mr. Warren’s First Amendment rights and the Florida Constitution in a rush to judgment. “The actual facts,” Judge Robert L. Hinkle wrote, “did not matter. All that was needed was a pretext.” Mr. DeSantis’s office, the judge said from the bench, had conducted a “one-sided inquiry” meant to target Mr. Warren. (The judge said he did not have the authority to reinstate Mr. Warren, who is appealing in state and federal court.)

Mr. Warren, in an interview, said he believed Mr. DeSantis had disregarded the will of the voters in his county for political gain.

“He’s willing to abuse his power to attack his political enemies,” Mr. Warren said.

Mr. DeSantis, who declined to be interviewed, insists in his new book, “The Courage to Be Free,” that his action was justified by Mr. Warren’s public statements. He argues that prosecutors who want “to ‘reform’ the criminal justice system” should quit and run for the Legislature.

In response to written questions, a spokesman for the governor referred to public statements and the trial record, adding, “Mr. Warren remains suspended from the office he failed to serve.”

Earlier this month, he told donors at a private gathering in Palm Beach that because he’d won only 50 percent of the vote in his 2018 election, people had told him to tread lightly.

“But I won 100 percent of the executive power,” he said, “and I intended to use it to advance an agenda that I campaigned on.”

Midway through a meeting with his closest advisers in December 2021, Mr. DeSantis abruptly asked a pointed question: Did they know of any prosecutors in the state who weren’t enforcing the law?

The topic was not on the meeting’s agenda, but it hardly came out of the blue.

Right-wing pundits and podcasters had for years railed against local prosecutors elected on platforms promising alternatives to incarceration for nonviolent crimes or avoiding the death penalty. The critics painted those prosecutors as agents of George Soros, the billionaire Democratic donor, and as giving rise to a scourge of crime. One such prosecutor at the time, Chesa Boudin, was facing a recall election in San Francisco.

A top DeSantis aide, Larry Keefe, set out to answer the governor’s question. A former United States attorney, Mr. Keefe’s title is public safety czar. But he has served in a broad role for the governor, executing high-profile projects including helping to coordinate the flight of scores of migrants to Martha’s Vineyard in September.

Mr. Keefe began by asking Florida sheriffs whether they knew of any progressive prosecutors. Several mentioned the state attorney from Hillsborough County. Communicating over encrypted text messages and personal email, Mr. Keefe assembled a dossier on Mr. Warren’s policies and charging decisions.

Mr. Warren was the only prosecutor he scrutinized, Mr. Keefe said later in a deposition: “All roads led to Mr. Warren.”

A former federal prosecutor, Mr. Warren, 46, was elected in 2016 promising to create a new unit to search for wrongful convictions, focus resources on prosecuting violent offenders, reduce prosecutions for first-time misdemeanors and curb the number of children charged as adults.

After Mr. DeSantis took office in 2019, Mr. Warren became a frequent critic. When the governor barred local governments from enacting their own Covid restrictions, Mr. Warren called the order “weak and spineless.” In 2021, he sought to organize opposition to a DeSantis-backed law that restricted political protests. In January 2022, Mr. Warren instituted a policy that made prosecutions of pedestrians and bicyclists for resisting arrest an exception rather than the rule, responding to studies that show the charge disproportionately affected Black people.

Florida’s Constitution allows governors to suspend local office holders for reasons including “malfeasance” or “neglect of duty” until the Legislature votes on whether to permanently remove or reinstate them. Mr. DeSantis was the first Florida governor in many decades known to have suspended an elected prosecutor over a policy difference.

By contrast, his predecessor, Rick Scott, publicly clashed with a prosecutor who refused to seek capital punishment and took death penalty cases away from her, but he did not force her from office.

For months, Mr. Keefe’s dossier on Mr. Warren failed to cross the threshold to take action against him, Mr. DeSantis’s lawyers later testified. Then, in June, after the Supreme Court overturned the federal right to an abortion, an advocacy group released a statement signed by Mr. Warren and 91 other prosecutors around the country.

In it, they vowed to “exercise our well-settled discretion and refrain from prosecuting those who seek, provide or support abortions.”

Whether the pledge would have any practical impact in Hillsborough County was unclear. Criminal cases of any kind involving abortion had been exceptionally rare in Florida. A new law banning abortions after 15 weeks of pregnancy was being appealed.

Mr. Warren told a TV reporter that the statement should not be read as a blanket policy: He would individually evaluate any cases that emerged. The governor’s aides saw the TV report and disregarded it, according to court records.

Ryan Newman, the governor’s general counsel, and Ray Treadwell, Mr. Newman’s deputy, testified that the pledge was the evidence they needed. Mr. Warren had said he would not enforce abortion laws, and could therefore be considered negligent and incompetent.

The lawyers discussed asking Mr. Warren to clarify whether his pledge would apply to existing abortion restrictions. But they decided not to, one later testified, because they worried that this would have “tipped him off” and given Mr. Warren a chance to walk it back, short-circuiting their effort to remove him.

Records obtained through litigation show that Mr. Keefe and the lawyers began drafting the executive order suspending Mr. Warren.

The tone of an early draft, written by Mr. Keefe in July, was highly partisan. The document named Mr. Soros six times, pointing to reports that Mr. Warren had received indirect support for his campaign from the billionaire Jewish philanthropist, a frequent target of conservatives and of antisemitic tropes.

(In a deposition, Mr. Keefe said he had not known that Mr. Soros was Jewish, but said he was “concerned” that “one of Florida’s state attorneys had been co-opted” by the philanthropist.)

In another draft, Mr. Treadwell highlighted a passage referring to Mr. Soros and wrote, “I would prefer to remove these allegations, but they may be valuable for the larger political narrative.”

The signed executive order included no references to Mr. Soros.

On July 26, Mr. Newman, Mr. Keefe and James Uthmeier, the governor’s chief of staff, met with Mr. DeSantis to present their plan, according to sworn deposition testimony.

The governor was initially skeptical, transcripts show. He questioned whether Mr. Warren could be removed based on his signed pledge alone, lacking evidence that he had declined to prosecute an abortion-related crime.

Mr. Newman argued that Mr. DeSantis should act while Mr. Warren’s refusal to prosecute was still hypothetical: It could be both impractical and unwise to wait to challenge Mr. Warren over a specific decision, Mr. Newman explained under oath at trial.

Mr. DeSantis was persuaded. He asked for additional information about Mr. Warren’s record but gave a green light to charge ahead.

Still, the governor seemed reluctant to hang Mr. Warren’s removal narrowly on the abortion pledge.

In handwritten instructions on a draft of the executive order, he told his lawyers to list “non-abortion infractions first,” including language accusing the prosecutor of “acting as if he is a law unto himself.”

Mr. DeSantis also crossed out three paragraphs packed with statistics about prosecution rates in Hillsborough County. Aides had dug up the data in hopes of showing a declining rate of prosecution during Mr. Warren’s tenure, but the numbers weren’t clear.

“You can kind of tell we didn’t have any definitive proof of a correlation,” Mr. Treadwell later testified.

In December, during a three-day trial over Mr. Warren’s removal, Judge Hinkle, an appointee of President Bill Clinton, said the evidence suggested that the goal of the governor’s review of Mr. Warren’s record was really “to amass information that could help bring down Mr. Warren, not to find out how Mr. Warren actually runs the office.”

“A cynic would say, ‘I just needed one pelt — just needed to nail one pelt to the wall,’” the judge added.

The day before he was suspended, Mr. Warren and his staff were putting the finishing touches on a major announcement set for the next day: indictments in two decades-old rape and murder cases.

Aides to Mr. DeSantis were planning a starkly different event, the legal records show.

Mr. Keefe was sending over talking points for Susan Lopez, a state judge who had agreed to replace Mr. Warren.

“Love it!” Ms. Lopez texted Mr. Keefe. “Sounds like me!”

Christina Pushaw, the governor’s spokeswoman at the time, teased the coming news on Twitter: “Major announcement tomorrow morning” from Mr. DeSantis, she wrote. “Prepare for liberal media meltdown of the year.” Her tweet alone generated headlines by Fox News and other conservative news outlets.

But Mr. DeSantis wanted to avoid the appearance that his ouster of Mr. Warren was an overtly partisan act.

He told Ms. Pushaw he was displeased with her tweet, she later testified, saying he wanted the public message to be about protecting Floridians from a dangerous prosecutor, adding that his decision “had nothing to do with the media.”

Ms. Pushaw, a combative force on social media, called this the only time the governor had ever “reprimanded” her over her tweets.

And Mr. Uthmeier, the governor’s chief of staff, warned another aide that Mr. DeSantis wanted them to tone down the “sensationalism.”

“Every comment impacts what will be contentious litigation,” Mr. Uthmeier wrote in a text message disclosed in litigation.

The heated language, however, was coming from the legal department, too. Mr. DeSantis’s general counsel, Mr. Newman, added language to the governor’s speech calling Mr. Warren “a woke ideologue masquerading as a prosecutor.”

Under oath, Mr. Newman later said he did not believe the statement to be true. He wrote it, he said, “to channel what I think the press shop wants.”

That press shop was in high gear as the governor’s office removed Mr. Warren. It discussed handing out copies of the executive order to friendly news outlets. Other aides, meanwhile, contacted Republican Party groups to to find DeSantis supporters to fill the room.

A few minutes before 10 a.m. on Aug. 4, Mr. Warren received an email notifying him that he had been suspended. He rushed to his office, but Mr. Keefe soon arrived with an armed sheriff’s deputy and ordered him to leave, according to testimony from Mr. Keefe. Mr. Keefe texted the governor’s staff: “Warren is out of the building.” And the news conference began.

With Mr. Warren out, the governor’s office stepped in. Mr. Keefe and Taryn Fenske, the governor’s communications chief, had already discussed in text messages what Ms. Lopez’s first steps should be, planning for the new state attorney to issue a memo rescinding Mr. Warren’s prosecution policies.

A memo that Ms. Lopez sent out days later mirrored that plan, saying, “The legislature makes the law and we, as prosecutors, enforce it.” (She testified that she did not recall consulting with anyone other than her chief of staff.)

Two aides to the governor were dispatched to the state attorney’s office in Hillsborough to “help make sure there’s no funny business over there,” Savannah Kelly Jefferson, director of external affairs, wrote in a text message to her staff.

Mr. Keefe, who had stuck around at the state attorney’s office, told Melanie Snow-Waxler, the office’s chief communications officer, to cancel Mr. Warren’s news conference on the cold cases, she said in an interview. The office said its chief of staff had made the decision.

He listened in on a speaker phone as she called one murder victim’s aunt to tell her not to come.

“I was confused. I didn’t know what was going on,” Ms. Snow-Waxler, who was fired soon after for reasons that are in dispute, said in the interview. “This is not someone who has been your boss, but it’s not like I was given an option. It was an order.”

A former DeSantis spokesman, Fred Piccolo, was brought in as a communications consultant for the state attorney’s office. In an interview, Mr. Piccolo said his job included keeping the prosecutor’s office on the same page with the governor’s office in publicly discussing Mr. Warren’s suspension. In a text message to colleagues, Ms. Fenske said she would lean on Mr. Piccolo to push back on Mr. Warren’s contention that his suspension was invalid: “We’ll put the nail in the coffin.”

Six days later, as the controversy continued to generate headlines and Mr. Warren publicly blasted his dismissal, the Hillsborough County state attorney’s office received a curious piece of correspondence from the governor’s office, documents from a public records request show.

It was from Mr. Treadwell, the governor’s deputy general counsel, making his first request for information from the prosecutor’s office that might reveal whether Mr. Warren had done anything wrong.

Jonathan Swan and Frances Robles contributed reporting.