ALBANY — Republicans appear to have retaken control of the state Senate this afternoon after two dissident Democrats crossed the aisle in a parliamentary coup.

“An historic change in leadership is taking place at this moment and a new bipartisan, coalition is being established that is bringing real reform to the Senate RIGHT NOW,” according to a news advisory sent out by the GOP.

The Associated Press reported that two Democrats — Hiram Monserrate of Queens and Pedro Espada, Jr. of the Bronx — are poised to announce that they have decided to caucus with the GOP out of anger at Senate Majority Leader Malcolm Smith.

The flip gives Republicans a 32-30 edge in the chamber and ensures that Smith is no longer the majority leader.

Democrats tried to leave the chamber at one point — even turning off the lights briefly before order was restored.

Democrats said they plan to take the fight to court.

In a statement sent out by Smith’s office, a spokesman called the move “illegal and unlawful”

“Nothing has changed, Senator Malcolm A. Smith remains the duly elected Temporary President and Majority Leader,” the spokesman added. “The real Senate Majority is anxious to get back to governing, and will take immediate steps to get us back to work.”

The coalition immediately approved a thick new list of rules for governing the chamber. It adjourned until Wednesday, when it plans to return to run the Senate.

“It’s a great day for the state of New York,” said B. Thomas Golisano, the Rochester billionaire, in a news conference with Libous, Skelos and Monserrate. Golisano, who has run unsuccessfully for governor three times, has spent millions to support candidates he feels will reform Albany to become more democratic and supportive of business.

The move was secretly in the works for more than five weeks, said a Republican with knowledge of the plan. Golisano was a major player in creating the coalition, said the Republican, who spoke on condition of anonymity because he wasn’t authorized to speak for the GOP senators.

New York’s government is run by the near absolute control of the majority party and its top leaders. Monday’s action, if it holds, would create the first coalition in power for at least 50 years.

The effort was a surprise in a Capitol where leaks and counter-leaks are common. It follows a tumultuous period since Democrats won their first majority in nearly a half-century. Espada, Monserrate, Diaz and Sen. Carl Kruger of Brooklyn challenged the nascent majority immediately, threatening to side with Republicans if the Democratic conference didn’t give them specific leadership posts and policy considerations, including a promise that a same-sex marriage bill never reach the floor.

Diaz stayed in the chamber but didn’t vote with the coalition.

Sen. John Bonacic of Orange County said Republicans sought Democrats who would support their reforms, including powerful controls over financing, staff and legislation that the GOP used while it was the majority party.

“We found two good men to step up,” Bonacic said.

The coup throws into doubt the movement to legalize same-sex marriage, one of the major policy issues still in the balance for the last two weeks of the regular session. Although passed in the Democrat-led Assembly, it is stalled in the Senate. Several Republicans and Sen. Ruben Diaz, a Bronx Democrat oppose the measure.

“If it doesn’t wipe it out, it puts a great mountain in front of it,” said the Rev. Duane Motley, founder of New Yorkers for Constitutional Freedoms, which has opposed same-sex marriage on religious grounds.