WASHINGTON — In the three days after the Democrats captured the House, President Trump fired his attorney general and replaced him with a loyalist critical of both the courts and the Russia investigation. He banned a CNN correspondent from the White House, while threatening he would do the same to other journalists. And he accused election officials in Florida and Arizona of rigging the vote against candidates he had campaigned for.

It was a remarkable assault on the nation’s institutions, even by a president who has gleefully taken a hammer to the press, to judges and prosecutors he does not like, and to an electoral process he has denounced as fraudulent since the day he took office.

Mr. Trump’s actions suggested a president lashing out after a midterm election loss that he had initially cast as a victory. Now he is girding for battle with a newly empowered Democratic opposition — one armed with subpoena power and a long list of questions about his conduct in office and ties to Russia — and it has brought out a fresh aggressiveness in him.

While each of his actions rattled Washington, Mr. Trump’s appointment of Matthew G. Whitaker as the acting attorney general, replacing the ousted Jeff Sessions, raised the thorniest ethical and legal questions, according to lawyers and former Justice Department officials.