Oklahoma Attorney General Scott Pruitt was narrowly confirmed Friday afternoon to lead the federal agency he built a career fighting.

The Senate voted 52-46 to install Pruitt as administrator of the Environmental Protection Agency, after a heated debate.

While Democrats have blasted the nominee for his push to roll back regulations and his past statements challenging the science behind climate change, his bid more recently was complicated by a dispute over documents.

On the eve of his confirmation, Pruitt was ordered by an Oklahoma judge to hand over thousands of emails between his office and fossil fuel companies like Koch Industries and the National Coal Council to the Center for Media and Democracy, which requested the collection of emails in 2014.

CMD is accusing Pruitt and the Oklahoma attorney general’s office of ignoring multiple open records requests.

Oklahoma County District Judge Aletia Haynes Timmons said “there was an abject failure to provide prompt and reasonable access to documents requested.”

As of Thursday night, the attorney general’s office had provided only 411 of the more than 3,000 emails CMD requested. The 411 emails were turned over earlier this week. The open records request was made two years ago.

Pruitt’s office maintains they have done nothing wrong and that they handle requests on a “first-come, first-served system.”

Democrats used the developments to push for a delay in Pruitt’s confirmation vote but were repeatedly denied.

“Scott Pruitt and Senate Republicans have made a mockery of the confirmation process, permitting the nominee to escape scrutiny and hide his deep ties to the fossil fuel industry,” Sierra Club Legislative Director Melinda Pierce said in a written statement. “What is he hiding in all of these emails?”

Senate Majority Leader Mitch McConnell slammed efforts to postpone it as another delay tactic by Democrats that was “unprecedented, harmful and pointless.”

“It’s one thing to obstruct to get some outcome, really these are a collection of futile gestures, not changing the outcome of these nominations,” he said from the Senate floor Friday.

Sen. Al Franken, D-Minn., pushed back on the accusations from Republicans that Democrats are purposely trying to stall the vote to get back at Trump.

“We have a nominee here who has sued the EPA 18 times!” Franken said. “We don’t think this nominee is qualified. It has nothing to do with us not recognizing the results of the election.”

Open records aside, Pruitt’s nomination has been controversial from the start.

As attorney general of Oklahoma, he sued the very department he was tapped by President Trump to run 14 times, often joining forces with the country’s largest fossil fuel companies against the EPA. He’s also openly questioned the science of climate change and challenged data that says humans contribute to global warming.

Pruitt’s also argued the EPA should have most of its authority stripped. His open antipathy for the department had many wondering why he’d want to lead it.

The New York Times reported that employees of the EPA have been calling their senators to urge them to vote against Pruitt. The display of defiance foreshadows turmoil between those employed by the agency and a man who has built a career on fighting it.

“It seems like Trump and Pruitt want a complete reversal of what EPA has done,” Nicole Cantello, an EPA lawyer who heads the Chicago branch of the union representing EPA’s 15,000 employees nationwide. “I don’t know if there’s any other agency that’s been so reviled. So it’s in our interest to do this.”

Republican lawmakers supporting Pruitt say he’s the right man to “modernize the agency” and will work to make sure the EPA doesn’t overstep its authority.

“He has consistently fought against federal intrusion,” Sen. Orrin Hatch, R-Utah, said. “The EPA must accept the limits of federal power.”

Sen. Dan Sullivan, R-Alaska, also supported Pruitt’s nomination. He argues Pruitt will clean up the EPA which he says has abused its power over the past eight years.

“We’ve had an agency that doesn’t list mistakes, ignores rule of law… and believes it has the power to regulate every nook and cranny of American life.” Sullivan said in a floor speech. “It’s been an enormous power grab. They regulate puddles.”

Despite the pushback, Pruitt’s confirmation seemed to be a done deal. Two Democratic senators, North Dakota’s Heidi Heitkamp and West Virginia’s Joe Manchin, announced earlier they would vote in favor of his confirmation.

On the Republican side, Sen. Susan Collins of Maine opposed it. Sen. John McCain, R-Ariz., skipped the vote to attend a conference in Germany.