The vote was 92 to 5.
In June, Trump nominated Wray to succeed James Comey as FBI director.
During his confirmation hearing, Wray told the Senate Judiciary Committee that he would strive for independence .
"If I am given the honor of leading this agency, I will never allow the FBI's work to be driven by anything other than the facts, the law and the impartial pursuit of justice. Period. Full stop," Wray said in July.
His comments came after Comey alleged that Trump had asked him for loyalty.
Trump terminated Comey in May amid a federal probe into Russian attempts to influence the 2016 election and whether the Trump campaign coordinated with Moscow. Trump later said he ousted Comey while thinking about the "Russia thing."
Wray, 50, is a white-collar lawyer who served as assistant attorney general during the George W. Bush administration. He previously led the federal investigation of Enron and represented Gov. Chris Christie in the Bridgegate scandal.
— CNBC's Ted Kemp and Jacob Pramuk contributed to this report.