The U.S. Senate this afternoon confirmed President Trump's nominee to lead the Environmental Protection Agency, Scott Pruitt, even as he faces a new court order.

An Oklahoma district court judge Thursday ordered Pruitt, the state's former attorney general, to turn over thousands of communications with major coal, oil and gas companies from his time in office.

The nonprofit watchdog Center for Media and Democracy had requested the public records two years ago, and the judge ruled there had been an "unreasonable" delay in responding to the request, demanding that Pruitt comply by the end of the day Monday.

The Senate confirmed his nomination this afternoon, 52-46, even after Democratic senators expressed outrage overnight that Republicans were going ahead as scheduled, despite the judge's ruling.

One Republican, Sen. Susan Collins of Maine, who had said she would vote no before Thursday's news of the court ruling, held to her vow to vote against Pruitt today. Another, Sen. John McCain, R-Ariz., skipped the vote, as did Sen. Joe Donnelly, D-Ind.

But two Democrats -- Sens. Heidi Heitkamp of North Dakota and Joe Manchin of West Virginia - voted for the controversial nominee, giving him the votes he needed.

Democrats had pushed Pruitt during his confirmation hearing last month about whether he used a private email account for state business and had turned over all of those messages. They say the records could prove improper connections. For years Pruitt has been accused of siding with oil and energy companies in exchange for campaign donations, which he denied at his hearing.

Asked by one senator whether he solicited money from a number of energy companies while attorney general, Pruitt, 48, said he "attended fundraising events as an attorney general along with other attorneys general" and denied asking several energy companies for money.

He also said he worked to represent the "voices of all Oklahomans," including the energy industry that has a major role in his state.

Pruitt has faced fierce opposition from the country's leading environmental organizations since his nomination was announced in December.

He has spent much of his career suing the EPA -- 14 times in total -- over clean water regulations, limits on carbon pollution from power plants, and new standards for mercury and other air toxins. Pruitt had described himself on the attorney general website as a leading advocate against the "activist" agenda of the EPA.

Michael Brune, executive director of the environmental Sierra Club, said his organization, 2.7 million members strong, was prepared to fight the incoming administration in court and push environmentally minded reforms in the marketplace under a secretary Pruitt.

"He is unfit to serve in this position," Brune told ABC News last month. "He is dangerous to the EPA.

Brune accused Pruitt of lacking the "basic knowledge" to head the agency tasked with keeping the country's environment safe and clean.

Republicans, though, have stood by Pruitt. Senate Majority Leader Mitch McConnell, R-Ky., congratulated him on the nomination and immediately offered his support.

"The EPA is the poster child for agencies in need of immediate reform and Scott has the resume and energy to turn this bureaucracy around," he wrote in a statement. "I'm confident he will work to find reasonable solutions rather than simply working to grow the reach and power of the federal bureaucracy."

But nearly 450 former EPA officials wrote to Congress last week urging Senators to vote against Pruitt today.

In the letter, the former government officials wrote, in part, "every EPA Administrator has a fundamental obligation to act in the public's interest based on current law and the best available science. Mr. Pruitt's record raises serious questions about whose interests he has served to date and whether he agrees with the longstanding tenets of U.S. environmental law."

Even current employees at the EPA have been protesting his nomination, with the union president of the American Federation of Government Employees National Council of EPA Locals No. 238 telling ABC News he is bracing for large-scale budget rollbacks.

For Pruitt's part, he praised the work of agency staff in his prepared opening remarks at the confirmation hearing.

"It will be my absolute privilege to work with the thousands of dedicated public servants at EPA who have devoted their careers to helping realize this shared goal," he said.

"I've always said that if you love what you do, you'll never work a day in your life, and I know those who work at EPA do so because of their tireless dedication to what they do."