Repeated comments from President Trump and his advisers about barring Muslims from entering the United States were at the heart of the decision on Monday by the acting attorney general, Sally Q. Yates, to refuse to defend the president’s executive order on immigration, senior officials involved said. Within hours of alerting Justice Department lawyers of her decision, the White House summarily fired her late Monday night.
The firing capped three days of internal deliberations at the Justice Department. Like many others in the government, Ms. Yates, a holdover from the Obama administration, was caught by surprise Friday night by Mr. Trump’s executive order temporarily halting all refugees from entering the country and indefinitely blocking immigration or visits from seven Muslim countries.
The Justice Department’s Office of Legal Counsel had reviewed the order and signed off on its legality. But Ms. Yates and her staff lawyers believed that the department had to consider the intent of the order, which she said appeared designed to single out people based on religion.
Mr. Trump had campaigned on a promise to single out Muslims for immigration restrictions. One of his advisers, Rudolph W. Giuliani, the former mayor of New York, said in an interview that Mr. Trump wanted a Muslim ban but needed “the right way to do it legally.” Mr. Trump said in a later interview with the Christian Broadcasting Network that Christian refugees would be given priority for entry visas to the United States.
In meetings on Monday, some lawyers believed the department should defend the order, as it normally does. Others disagreed. Ms. Yates considered resigning, the officials said, but concluded that doing so would leave the decision to whomever succeeded her, even if in a temporary capacity.
So on Monday evening, she issued a stinging rebuke of the president and ordered government lawyers not to defend the ban in court, where it is being contested.
“I am not convinced that the defense of the executive order is consistent with these responsibilities, nor am I convinced that the executive order is lawful,” Ms. Yates wrote in a letter to lawyers at the Justice Department, referring to her obligations as acting attorney general.
Ms. Yates, who was deputy attorney general for the last year and a half of the Obama administration, was running the department temporarily until the Senate could confirm a replacement. Her order was in effect for only a matter of hours before a White House courier arrived at the Justice Department with a handwritten letter.
“Dear Deputy Attorney General Yates,” the letter said. “I am informing you that the president has removed you from the office of Deputy Attorney General of the United States.” It was signed by John DeStefano, an assistant to Mr. Trump.
Democrats hailed her as a hero. But while Ms. Yates was a reliably liberal voice on issues of civil rights, criminal justice and sentencing, she spent decades working as a career prosecutor in Atlanta under administrations from both parties. She prosecuted Eric Rudolph, known as the Olympic Park bomber, and was viewed as an aggressive white-collar prosecutor. Senator Johnny Isakson, Republican of Georgia, introduced her at her confirmation hearing in 2015.
“She will be a hero of the American people, a hero of what’s right,” Mr. Isakson said at the time. “She’ll call them like she sees them, and she will be fair, and she will be just.”
At those hearings, Republicans were furious about former President Barack Obama’s order liberalizing immigration policy and questioned Ms. Yates about whether she would be willing to stand up to the president. Senator Jeff Sessions, Republican of Alabama and Mr. Trump’s nominee for attorney general, was particularly pointed in his questioning.
“If the views the president wants to execute are unlawful, should the attorney general or the deputy attorney general say ‘No?’” Mr. Sessions asked.
“I believe the attorney general or deputy attorney general has an obligation to follow the law and Constitution and give their independent legal advice to the president,” Ms. Yates replied.
As deputy attorney general, Ms. Yates was the department’s leading voice on issues of clemency and sentencing reform and led the push for prosecutors to bring charges against individual executives involved in corporate wrongdoing.
Ms. Yates and Attorney General Loretta E. Lynch earned the ire of Democrats — including many in the department — for not intervening and prohibiting the F.B.I. director, James B. Comey, from sending a letter to Congress in the final days of the presidential campaign. The letter raised the prospect of new and potentially damaging evidence against Hillary Clinton related to an investigation that had been closed. Nothing came of the new evidence, and Mrs. Clinton’s team says the letter cost her the presidency.
Former Attorney General Eric H. Holder Jr., a Democrat, posted a photograph of Ms. Yates on Twitter late Monday and said, “This is what skill, judgment and courage look like.”
Republicans disagreed, including George J. Terwilliger III, a former deputy attorney general who, like Ms. Yates, briefly served as acting attorney general. “In a legal dispute in our adversary system concerning an executive order, the attorney general’s and the Justice Department’s responsibility is to be an advocate for the president’s position,” he said.
He said Ms. Yates’s actions “makes her and the Justice Department look blatantly political.”