ALBANY — Major cracks opened in Republican opposition to gay marriage last night as a key GOP senator dramatically endorsed the measure and put New York on the verge of legalizing same-sex nuptials.

Sen. James Alesi’s stunning change of heart came with a shocking confession that his anguished vote against gay-marriage legislation two years ago was motivated purely by politics as his party battled to retake control of the narrowly divided state Senate that year.

“It was a political vote,” Alesi (R-Rochester) told reporters after emerging from a closed-door meeting with Gov. Cuomo and other gay-marriage advocates.

“I was supporting the conference vote that I thought at the time politically was necessary when we were in the minority. We are no longer in the minority.”

Alesi said he would now support the bill as long as it, like the earlier legislation, includes protections to ensure religious organizations won’t be forced to conduct marriages in conflict with their beliefs.

“I believe that if you live in America and you expect equality and freedom for yourself, you should extend it to other people,” Alesi said.

Earlier, Cuomo appeared in the ceremonial Red Room with three of the four remaining Senate Democrats who voted against gay marriage two years ago to announce the trio had agreed to support the measure.

Alesi and the flip-flopping Democrats — Carl Kruger of Brooklyn and Joseph Addabbo and Shirley Huntley of Queens — put a same-sex marriage bill just two votes shy of passage in the 62-seat Senate.

The political maneuvering came as both houses of the Legislature last night certified another marquee win for Cuomo by approving a sweeping overhaul of state ethics rules that requires lawmakers to fully disclose their outside income.

The gay-marriage developments put intense pressure on Senate Majority Leader Dean Skelos (R-Nassau) to allow a vote this week on the bill.

The Post reported yesterday that as many as six of the Senate’s 32 Republicans appeared poised to support the measure but feared a backlash from the state’s powerful Conservative Party.

One reportedly wavering Republican, Sen. Kemp Hannon (R-Nassau), insisted he was voting no but admitted that his position was based largely on concern for his political future.

Skelos initially told reporters that Republicans would take up the issue behind closed doors today, but after Alesi’s announcement, a spokesman for the leader said the powwow might not come until tomorrow.