WASHINGTON — NASA’s latest nail-biting drama was far from orbit as the Senate narrowly confirmed President Donald Trump’s choice of a tea party congressman to run the space agency in an unprecedented party-line vote.

In a 50-49 vote Thursday, Oklahoma Rep. James Bridenstine, a Navy Reserve pilot, was confirmed as NASA’s 13th administrator, an agency that usually is kept away from partisanship. His three predecessors — two nominated by Republicans — were all approved unanimously. Before that, one NASA chief served under three presidents, two Republicans and a Democrat.

The two days of voting were as tense as a launch countdown.

A procedural vote Wednesday initially ended in a 49-49 tie — Vice President Mike Pence, who normally breaks a tie, was at Trump’s Mar-a-Lago estate in Florida — before Arizona Republican Jeff Flake switched from opposition to support, using his vote as leverage to address an unrelated issue.

Thursday’s vote included the drama of another delayed but approving vote by Flake, a last-minute no vote by Illinois Democrat Tammy Duckworth — who wheeled onto the floor with her 10-day-old baby in tow — and the possibility of a tie-breaker by Pence, who was back in town.

NASA is a couple years away from launching a new giant rocket and crew capsule to replace the space shuttle fleet that was retired in 2011.

“I look forward to working with the outstanding team at NASA to achieve the president’s vision for American leadership in space,” Bridenstine said in a NASA release after the vote.

Democrats opposing Bridenstine said his outspoken divisiveness, earlier rejection of mainstream climate change science and lack of space experience made him unqualified. Republicans praised him as a qualified war hero.

“His record of behavior in the Congress is as divisive as any in Washington, including his attacks on members of this body from his own party,” Florida Democrat Bill Nelson said. “It’s hard to see how that record will endear, and by extension NASA, him to Congress, and most importantly, endear him to the American people. ”

Sen. Edward Markey, a Massachusetts Democrat, cited past Bridenstine comments that rejected mainstream climate science, invoking the movie “Apollo 13.”

“Houston, we have a problem,” Markey said. “NASA’s science, NASA’s mission and American leadership will be in jeopardy under Congressman Bridenstine’s leadership.”

During his confirmation hearing, Bridenstine said he acknowledges that global warming is real and man-made, but wouldn’t say that it was mostly human-caused, as the overwhelming majority of scientists and scientific literature do. And Bridenstine told Nelson, “I want to make sure that NASA remains, as you said, apolitical.”

Texas Republican Ted Cruz praised the NASA nominee as “a war hero.”

“NASA needs a strong leader and it will have that strong leader in Jim Bridenstine,” Cruz said.

Sean O’Keefe, who was NASA chief under President George W. Bush and was confirmed unanimously, said the close vote “is a consequence of an erosion of comity in the Congress, particularly in the Senate. Political fights will always break out, but now most policy choices are more likely to emerge based on the party with the majority than the power of the idea.”

Alan Ladwig, a top NASA political appointee under Democrats, said this was a case of both party politics and a divisive nominee who doesn’t accept science.

__

Associated Press writers Mary Claire Jalonick and Lisa Mascaro contributed to this report.