In a historic triumph that set off a political earthquake in Albany, the Democrats last night won a majority in the state Senate for the first time in 40 years.

They’ll now control both houses of the Legislature as well as the governor’s office – the first such triple play they’ve managed to score since 1935.

As of early this morning, the Democrats had locked up at least 32 of the Senate’s 62 seats, with one race too close to call.

“This election has shown that people want change,” said the Senate’s top Democrat, Malcolm Smith of Queens, the current minority leader who’s expected to run for majority leader in January.

Two local Republican senators were unseated by Democratic challengers.

Caesar Trunzo of Suffolk County lost to Brian Foley, Brookhaven’s town supervisor. Trunzo had held the office since 1972.

Serphin Maltese of Queens, a 20-year veteran, lost handily to Joseph Addabbo Jr., a city councilman from Ozone Park. Also in Queens, veteran GOP senator Frank Padavan was locked in a nail-biter with Democratic Councilman James Gennaro.

Meanwhile, in western New York, the parties traded victories in two highly contested districts.

In Erie County, one of the Democrats’ brightest prospects, former boxer Joe Mesi, was on the ropes in a contest with Republican Michael Ranzzenhofer. The seat is now held by held by Republican Mary Lou Rath.

Before yesterday’s vote, Republicans held a slim two-seat majority in the Senate – their last bastion of power in Albany.

But the Democratic Senate success could be undercut by questions over the allegiance of four of the party’s senators from New York City, who have refused to commit to supporting Smith as their party leader.

Three of them have occasionally sided with the Republicans.

In the Assembly, the Democrats easily held onto their veto-proof majority.