Republican Sen. John McCain, who once called the vote to allow gays to serve openly in the military a “sad day,” is now, just six years later, emerging as a firewall against GOP efforts to erode LGBT protections in the hotly debated defense reauthorization bill.

Congress is poised for a showdown over a slate of measures focused on LGBT rights attached to the defense funding measure that, among other things, could allow religious organizations with federal contracts to be exempted from federal guidelines barring sexual orientation and gender identity discrimination. McCain, chairman of the Senate Armed Services Committee, has a measure that doesn’t include the exemptions - a move that is being lauded by gay rights groups.

Sen. John McCain, R-Ariz. Jacquelyn Martin / AP file

“McCain has changed because much of the country has shifted including the GOP,” said Julian Zelizer, a political historian at Princeton University. “Support for LGBT rights is incredibly strong and even within the military opinion has changed dramatically in recent years. In part, ‘don't ask, don't tell, a watered down compromise, opened the door for new attitudes and more reform. McCain has adjusted to these changes and as the leader of the Armed Services Committee has a powerful position to act as a firewall.”

The discussion on LGBT-related amendments to the defense policy bill comes less than a week after a gunman opened fire in a gay nightclub in Orlando in a shooting spree that left 49 dead and 53 others injured. The fact that the LGBT community was so directly targeted in the deadliest mass shooting in American history has brought into focus heated Congressional debate over protections against discrimination.

In aftermath of #ISIL inspired terror attack in #Orlando, we must not give into fear - we must defeat evil together https://t.co/4zus0e65Po — John McCain (@SenJohnMcCain) June 13, 2016

Last month, the House floor erupted in chaos after an amendment aimed at preventing federal contractors from getting government bids if they discriminate against members of the LGBT community failed to pass by one vote. Members of the Republican-controlled House convinced fellow party members to change their votes to block the measure’s passage in a vote that was held open longer to allow for the switch.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: Vote on House Floor Over LGBT Rights Turns Ugly

The change in McCain’s tone on gay rights is notable.

In just under a decade, the seasoned lawmaker and decorated Vietnam War veteran has gone from being reviled by the LGBT community for his impassioned opposition to gay and lesbian soldiers serving openly to supporting Eric Fanning, who is openly gay, in his historic bid to become secretary of the Army.

In April, McCain took to the Senate floor to plead with his friend and colleague, Sen. Pat Roberts, R-Kansas, to lift his hold on Fanning’s confirmation.

Secretary of the Army, Eric Fanning USAF

"It is not fair to the men and the women of the United States Army to be without the leadership of a secretary of the Army," McCain said on the Senate floor. "Mr. Fanning is eminently qualified to assume that role of secretary of the Army. So I would urge my friend and colleague to allow me to… to not object to the unanimous consent that I am just proposing."

Roberts eventually lifted his hold, which he said was related to concerns he had over Guantanamo Bay detainees being possibly moved to the Fort Leavenworth, Kansas military installation.

Related: Eric Fanning, First Openly Gay Army Secretary, Confirmed by U.S. Senate

McCain was also one of only a handful of Republicans to support a measure to block job discrimination based on sexual orientation or gender orientation. And he was vocal in his criticism of an Arizona measure to allow religious exemptions for businesses to refuse services to gays and lesbians.

McCain is facing a tough re-election challenge from Ann Kirkpatrick, a Democrat. In previous elections years, lawmakers have tended to vote on the defense bill after the general elections.

“McCain is in a tough re-election race, and he needs to broaden his coalition whenever he can. Discrimination against gays is now a big loser politically in most states, and that even includes Arizona - which is not nearly as conservative as it used to be,” said Larry Sabato, director of the Center for Politics at the University of Virginia.

Still, gay rights advocates and their allies say they are buoyed by McCain’s repositioning.

“We are seeing a swiftly growing number of people who had opposed LGBT rights based on their fiscal or national security views as part of a conservative package or worldview, like Senator McCain, de-link their fiscal or military positions from others' social conservative, anti-LGBT views and goals,” said Jennifer Pizer, senior counsel and director of Lambda Legal’s Law and Policy Project.

“This is an immensely important potential realignment not only in Congress but in state legislatures and many other venues. We often see these shifts in brightest light during election seasons. And sometimes they lead to civil rights progress thereafter. That, of course, is the goal," Pizer added.