The Senate confirmed William P. Barr on Thursday for a second stint as attorney general, handing oversight of the Justice Department — and its ongoing 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.

Senators expressed hope that the installation of a conventional figure like Mr. Barr could return some stability to the Justice Department’s 115,000 employees, after two years of intense battering by President Trump and his allies in Congress. The president lost confidence in his first attorney general, Jeff Sessions, early on and, after months of publicly scorning him for recusing himself from overseeing the Russia investigation, Mr. Trump installed Mr. Sessions’s chief of staff, Matthew G. Whitaker, as a temporary replacement in November.