Vice President Pence waves while arriving for a swearing-in ceremony in the Old Senate Chamber of the U.S. Capitol in Washington on Jan. 3. (Aaron P. Bernstein/Bloomberg)

The Senate narrowly confirmed Kansas Gov. Sam Brownback (R) to a diplomatic post Wednesday, with Senate GOP leaders needing the help of Vice President Pence to break a deadlock over his controversial nomination.

Brownback was confirmed to be ambassador at large for international religious freedom on a 50-to-49 vote, with all Democrats opposed and two Republicans absent. Pence cast the tiebreaking vote in his role as president of the Senate.

The vote highlighted how polarizing a figure Brownback has become during his tenure as governor of Kansas. It also underscored the razor-thin margin of the Senate Republican majority and the implications for the GOP agenda and President Trump's nominees.

Brownback had faced opposition from LGBT groups over a decision he made as Kansas governor to scuttle an executive order that barred discrimination based on sexual orientation or gender identity.

In a dramatic turn Wednesday afternoon, the Senate hit a 49-to-49 stalemate on a procedural vote to end debate on the nomination. Two Republican senators were absent: John McCain (Ariz.), who is in his home state battling brain cancer, and Bob Corker (Tenn.), who was at the World Economic Forum in Davos, Switzerland. Pence quickly traveled to the Capitol to break the deadlock.

Wednesday marked the seventh and eighth times Pence has had to cast a tiebreaking vote since the start of the Trump presidency just over a year ago. By comparison, Vice President Joe Biden cast no tiebreaking votes in the Senate during the eight years of the Obama presidency. During George W. Bush's presidency, Vice President Richard B. Cheney cast eight tiebreaking votes.

The GOP majority shrank to 51-to-49 when Democrats won an upset in the Alabama special election late last year, diminishing an already tight margin.

Brownback is a former senator. But that was not enough to win crossover support, even from some Democrats who had served with him.

"He's a former senator. But, things happen," said Sen. Richard C. Shelby (R-Ala.), with a chuckle.

In remarks on the Senate floor, Sen. Robert Menendez (D-N.J.) was critical of Brownback, saying his record on LGBT rights was troubling and expressing concern that he would defend only Christian minorities across the world.

"I do not take my vote against a former colleague's nomination lightly, nor do I question Governor Brownback's devotion to his own faith. Indeed, as person of faith myself, I admire it," he said.

But, Menendez added, "I was deeply disturbed that when pressed during his confirmation hearing, Governor Brownback could not even bring himself to muster a resounding no, that it is never acceptable for a government to imprison or execute an individual based on their sexual orientation."

Under Trump, the State Department folded its Office of Religion and Global Affairs into the Office of International Religious Freedom that Brownback will now lead. The restructuring gives him a larger profile.

Some advocates for religious freedom reacted with concern to the change, saying that the administration appeared not to care about the work that the Office of Religion and Global Affairs was doing. Others argued that the Office of International Religious Freedom will be significantly larger, and the change does not suggest that the Trump administration is uninterested in the subject.

Advocates for international religious freedom, particularly conservative Christian groups, have been asking the Trump administration to fill the vacant ambassadorship for months. When Pence spoke in May, for instance, to a conference organized by the Billy Graham Evangelistic Association about the persecution of Christians, one of the most frequent requests from the speakers in attendance was a new ambassador.

The most recent ambassador was Rabbi David Saperstein, the only non-Christian who has held the position. President Barack Obama appointed him in 2014.