New York state lawmakers on Monday passed a controversial bill granting driver’s licenses to illegal immigrants — and Gov. Andrew Cuomo is expected to sign it.

Democrats in the state Senate managed to pass the bill on a 33-29 vote, despite losing all six of their Long Island members over fears the bill could prove politically toxic in their swing districts.

“We are treating the people who have broken our law, who are criminals [like law-abiding citizens]. This legislation will lead to more illegal immigration,” Sen. Thomas O’Mara (R-Chemung) fumed as he voted against the measure.

But Sen. Jessica Ramos (D-Queens), a champion of the bill, shot back to naysayers during the debate, “Be careful, your xenophobia is showing.”

The Assembly OK’d the bill last week, and it now heads to Cuomo’s desk for his signature.

The Senate vote came after days of intense talks that were largely wrapped up over the weekend — and despite continued opposition from Long Island Democrats representing potentially competitive districts and an MS-13 gang crisis.

A recent Siena poll brought those fears home when it reported that voters statewide opposed the measure 53 to 41%, with 55% of independent voters against it.

The regional breakdowns weren’t much better: Only 40% of suburban voters favored it and upstate voters hated it even more with just 35% support.

Republicans pounded the Long Island Democrats before and during the Senate debate in a likely preview of political attacks to come in 2020 elections.

“Shame on the Democrats for bringing this bill to the floor — and the Long Island Democrats,” Senate Minority Leader John Flanagan (R-Suffolk) told The Post before the vote.

“The Democratic senators said they would get here and protect the interests of Long Island and they wouldn’t allow New York City to control and dominate the agenda. They have failed miserably.”

Monday’s vote moved the fight over driver’s licenses from the Assembly and Senate chambers to the governor’s office, where the bill awaits either Cuomo’s signature or veto.

Cuomo professed his support for the proposal for years, but threw supporters a last-minute curveball when he asked the state’s top civil attorney, Solicitor General Barbara Underwood, to review the measure for possible safety concerns — threatening to veto it if he didn’t like her assessment.

“You could create a database for the feds to use to actually track down undocumented people,” Cuomo said on WAMC radio. “California passed a law, and they are now in litigation.”

Underwood’s boss, Attorney General Tish James, released a statement amid the Monday-night vote arguing that the bill is legally sound.

“The legislation is well-crafted and contains ample protections for those who apply for driver’s licenses. If this bill is enacted and challenged in court, we will vigorously defend it,” she said.

The Counsel to the Governor, Alphonso David, later released a statement saying “the governor will sign the bill.”

Still, Cuomo’s last-minute move left supporters livid.

“None of these concerns were relayed to us. Why now?” bill sponsor Luis Sepulveda (D-Bronx) said Monday.

Proponents have long argued that the bill would improve safety on the roads by ensuring drivers are properly trained and licensed and that it would help better integrate New York’s estimated 265,000 illegal immigrants into the state’s economy and society.

Twelve other states and the District of Columbia already allow them to get licenses.

Republican opponents claim the bill could allow the illegal immigrants to register to vote.

“We can’t even get citizens to the polls to vote,” quipped supporting state Sen. Kevin Parker (D–Brooklyn), referring to the nation’s traditionally dismal voter turnout.

The vote was the culmination of a fight that first began in 2007 when then-Gov. Eliot Spitzer attempted to use his executive power to undo a requirement imposed after the 9/11 terror attacks that applicants must have a Social Security card to qualify for a driver’s license.

Spitzer backed down in the face of a massive rebellion from upstate Democrats and Republicans who assailed the move, which sent his poll numbers tumbling.

Additional reporting by Max Jaeger