The state teachers union got a new president and issued a long-threatened attack on the State Education Department during a dramatic meeting in New York City this weekend.

Karen Magee, head of the Harrison Association of Teachers in Westchester County, unseated Richard Iannuzzi, New York State United Teachers president since 2005, in an election seen by some as a power play by New York City’s union chief.

It was the first time in the union’s 42-year history that a sitting president was ousted.

Magee’s supporters — who included United Federation of Teachers President Michael Mulgrew and New York City’s NYSUT delegation — said she would offer a more aggressive approach to dealing with state education policy than Iannuzzi has brought to Albany. Under Iannuzzi’s leadership, the state teachers union agreed to teacher evaluation rules that are unpopular among educators.

Magee said she and the slate of officers elected with her would not avoid tangling with the legislature and Gov. Andrew Cuomo, the main proponents of the evaluation rules.

“Our team stands for change and our work begins now,” said Magee — a self-described “militant” — in a statement after the election. “That includes taking on the tough fights and communicating clearly with decision makers at every level. We will be the voice they cannot ignore.”

The ouster would not have been possible without support from the United Federation of Teachers, the city union, which makes up roughly one third of the state union’s membership. Early in the campaign, UFT president Michael Mulgrew acknowledged taking an active role in helping to bring about a leadership change, and Andrew Pallotta, a UFT member, was the only NYSUT officer to win reelection.

Mulgrew released a statement after the election congratulating Magee and pledging to work with her. “Teachers from every corner of the state have spoken, and their voices have been heard,” Mulgrew said in the statement.

Dissatisfaction with Cuomo and State Education Commissioner John King were the overarching themes of NYSUT’s annual conference. The union followed through on months-old plans to issue a no-confidence vote in King because of the way he has handled the rollout of the evaluation rules and Common Core standards. The vote called for King’s “immediate” removal.

Among the demands laid out in the resolution against King, the union said it would not support the Common Core without significant changes to the state’s education policies. Legislators signed off on several of those changes last week — including a ban on using test scores to set student promotion rules and on allowing the state to feed student data into a shared database.

The commissioner traditionally addresses the union at its annual assembly, which was held over the weekend in Midtown, but this year King wasn’t invited.

Said Maria Neira, who was unseated as the union’s vice president, “John King is the elephant who is not in the room.”