A day after an election that saw most of the union-backed candidates win their races, New York City teachers union president Michael Mulgrew was still celebrating. “We had a very good night,” he told me.

In total, 157 of the 170 candidates the United Federation of Teachers supported were victorious on Tuesday, union officials said.

Mulgrew said he was pleased to see former City Councilman Tony Avella take Republican Frank Padavan’s seat in the State Senate. A month before the election, when polls showed Avella was down by over two dozen points, Mulgrew said he sent union members to campaign in northeast Queens. Avella, who also ran and lost in the city’s mayoral race last year, ended up with 53 percent of the vote.

“It was fun because everyone told us we wouldn’t win,” Mulgrew said.

Union-backed candidates lost in 13 races. Among them was Democratic Congressman Michael McMahon, who was also endorsed by Mayor Bloomberg and was expected to hold onto his Staten Island seat, but lost to Republican Michael Grimm.

The union also lost races in the State Assembly, where two supporters of charter schools were reelected. Assemblyman Sam Hoyt and Jonathan Bing, both of whom were endorsed by the pro-charter school group Democrats for Education Reform (DFER), won. Before the election, Bing told a group of teachers that if he stayed in office, he planned to reintroduce a bill that would end seniority-based layoffs.

DFER also had a good night, faring far better than it did in the Democratic primary. It endorsed eight candidates in State Assembly races, all of whom won. The group supported 12 candidates for the State Senate, nine of whom won.

Though man of DFER’s causes are anathema to the teachers union, the two organizations supported nine of the same candidates. In the Senate, these candidates were Jose Peralta, Joseph Addabbo, John Sampson, Eric Adams, Daniel Squadron, and David Carlucci. In the Assembly, both groups backed Audrey Pheffer, Karim Camara, and Hakeem Jeffries.

One of DFER’s pro-charter school candidate’s future remains uncertain. The ballots are still being counted, but Democratic State Senator Craig Johnson is down by about 400 votes. State Democratic Party Chairman Jay Jacobs told Newsday today that he thinks Johnson has lost to Republican Jack Martins.

The future of the Senate’s leadership hangs on Johnson’s race, as well as two others that will determine whether the Democrats keep their slim majority.