TRENTON -- State Senate President Stephen Sweeney, the most powerful lawmaker in New Jersey, easily won re-election Tuesday despite an expensive and bloody effort by the state's largest teachers union to oust him from the seat he's held for nearly 16 years.

Sweeney, a Democrat, beat Republican Fran Grenier by about 9,000 votes or 18 percentage points -- 59 percent to 41 percent -- to keep the Senate seat in south Jersey's rural 3rd legislative district.

It was the most expensive legislative race in New Jersey history, with political experts expecting the final price tag to be around $20 million.

That's largely because the New Jersey Education Association spent more than $5 million to back Grenier and try to deny Sweeney, D-Gloucester, a fifth term.

"It was a waste of money," Sweeney told NJTV after the victory. "And I'm disappointed. Teachers are wonderful people who do great things for our children. But their leadership needs to be re-evaluated."

Though the union often endorses Democrats, it had soured on Sweeney over the years -- first for teaming with Republican Gov. Chris Christie to pass pension reform in 2011 and then for breaking a promise to press for a constitutional amendment forcing full pension payments each year.

There was also an incident in which Sweeney accused the union of threatening to withhold campaign contributions to Democratic candidates if the amendment didn't get on the ballot. Sweeney called it "bribery" and "extortion" and called on prosecutors to investigate.

The Democrat and his allies spent more than $10 million to thwart the union in the race.

Had Sweeney, 58, lost, it would have left Democrats scrambling to find a new leader of the upper house of the state Legislature, the body that makes New Jersey's laws.

With Tuesday's win, Sweeney simply hangs on to his seat in the Senate. Democrats in the chamber will meet over the next few days to select the Senate president. But Sweeney is widely expected to keep that post.

The NJEA drew criticism from Democrats for supporting Grenier, a former Woodstown councilman who has supported Christie -- the union's longtime foe -- and President Donald Trump in the past.

The battle against Sweeney also diverted millions that could have been spent supporting Democrats in other tough districts.

"We could have won a couple more seats, which would help Murphy's agenda going forward," Sweeney told NJTV.

Now, the union will likely start the next legislative session being viewed as an enemy by Sweeney and other Democrats in the Legislature, possibly hurting its agenda.

But experts said the NJEA was also trying to flex its political muscles by taking down Sweeney, warning other legislators not to cross them.

Sweeney won re-election the same night Democrat Phil Murphy won the race to succeed Christie as governor. Now, Democrats will control the governor's office and both houses of the Legislature for the first time since 2009.

But the relationship between Sweeney and Murphy has already shown signs of strain. Murphy, who was endorsed by the NJEA, was criticized for not picking a side in the battle between the union and Sweeney, who endorsed and campaigned with Murphy.

Still, Murphy campaigned with Sweeney at a rally with labor union members in Swedesboro on Election Day.

"I'm not blaming Phil Murphy for this," Sweeney told NJTV. "I'm not looking for a fight. I'm looking to move the Democratic agenda forward. ... I want to work with Phil, not fight him."

Marie Blistan, the NJEA's president, said Tuesday night she "could not be prouder of the effort that we made on behalf of all of our endorsed candidates."

"By working tirelessly for over a year to elect Phil Murphy, we have guaranteed a new direction for New Jersey after eight years of failed leadership," Blistan said in a statement. "By standing with our allies in the Legislature, we have maintained a strong foundation for the next legislative session. And by taking on difficult fights that forced us to stand firm for what we believe in, we showed New Jersey that we will not back down when our values are at stake."

Sweeney, the leader of an ironworkers union by trade, has represented the district since 2002. He became Senate president in 2010 -- the same year Christie took office.

Sweeney has been aligned with a south Jersey voting bloc with ties to powerbroker George Norcross III, arguably the most powerful non-elected Democrat in the state.

That helped him become a key leader in the Legislature, often crafting bipartisan deals with Christie.

Brent Johnson may be reached at bjohnson@njadvancemedia.com. Follow him on Twitter @johnsb01. Find NJ.com Politics on Facebook.