Mr. Bharara won convictions of more than a dozen lawmakers, culminating in 2015, when he brought down two of the state’s three most powerful politicians: Sheldon Silver, the Democratic former Assembly speaker, and Dean Skelos, the Republican former Senate majority leader. Both men have appealed their convictions, which included charges of bribery, extortion and money laundering.

Mr. Bharara also tangled repeatedly with the other member of that entrenched trio, New York’s governor, Andrew Cuomo. He investigated Mr. Cuomo’s suspicious disbanding in 2014 of the Moreland Commission, an anticorruption panel that Mr. Cuomo had established a year earlier to address the epidemic of self-dealing in state politics. Mr. Bharara eventually decided there was not enough evidence to charge the governor with interfering in the commission’s work, but at the time of his firing, Mr. Bharara’s office was prosecuting two of Mr. Cuomo’s former advisers in a bribery and bid-rigging scandal.

Mr. Bharara was an equal-opportunity prosecutor. One of the first cases as United States attorney for the Southern District of New York involved bank-fraud charges against a top Democratic donor, Hassan Nemazee, who had ties to Senator Chuck Schumer, for whom Mr. Bharara had worked as chief counsel and who had urged Mr. Obama to hire him.

At the time of his dismissal, his office was in the final stages of a criminal investigation into the campaign fund-raising of New York City’s mayor, Bill de Blasio.

It’s standard practice for United States attorneys to be replaced when a new administration takes office — roughly half of those appointed by President Obama had resigned before last Friday — but Mr. Trump, as president-elect, had personally asked Mr. Bharara to stay on during a meeting at Trump Tower in November. So why fire him now?