WASHINGTON — The Senate confirmed William P. Barr on Thursday for a second stint as attorney general, handing oversight of the Justice Department — and its investigation into links between Russia’s interference in the 2016 election and the Trump campaign — to a seasoned Republican legal hand known for his expansive view of presidential power.

Mr. Barr was sworn in hours later, beginning a new chapter for a department that has been battered by criticism from President Trump. The president lost confidence in and publicly scorned his first attorney general, Jeff Sessions, after he recused himself from overseeing the Russia investigation. The department was further rattled when Mr. Trump installed a relatively inexperienced loyalist, Matthew G. Whitaker, Mr. Sessions’s chief of staff, as a temporary replacement in November.

Mr. Barr faces an array of challenges, not least retaining the confidence of both Mr. Trump and Congress as he steers the department through the anticipated conclusion of the investigation by the special counsel, Robert S. Mueller III, and the question of whether and how to make any report from Mr. Mueller public.

Morale has suffered among the department’s 115,000 employees amid accusations that its work has been politicized. And Mr. Barr will presumably want to put his own stamp on the administration’s agenda following Mr. Sessions, who for all his problems with the president pushed successfully to put in place conservative policies on civil rights, voting rights, immigration, drugs, policing and crime, among other issues.