A $41 million fight that attracted national attention and divided the state's top political figures ended Tuesday night as opponents of a charter school expansion ballot question declared victory.

Voters shot down the question that would have allowed state officials to authorize up to 12 new charter schools or expansions per year, with priority given to lower-performing districts and those with higher demand for charters.

"We did this. We beat back the privateers," Massachusetts Teachers Association President Barbara Madeloni told supporters. She said, "We beat their money through democracy."

With 61 percent of the vote in, 62.6 percent were opposed to Question 2 with 37.4 percent in favor.

The failure of Question 2 means the law governing charter schools will remain unchanged. It also marks a loss for Gov. Charlie Baker, who made charter school expansion a campaign promise in 2014 and was among the measure's most vocal advocates.

Baker, in a statement, said he was "proud to have joined with thousands of parents, teachers and education reformers in a worthwhile campaign to provide more education choices for students stuck in struggling districts, and while Question 2 was not successful, the importance of that goal is unchanged."

Backed by teachers' unions, the New England chapter of the NAACP, more than 200 local school committees and the bulk of state lawmakers, opponents led a campaign that focused on the potential for charters to siphon away funding from traditional district schools. They also directed attention toward their goal of broad-based improvement in all public schools.

"We're fighting for equitable resources for all students, in whatever kinds of schools they go to," Citizens for Public Schools executive director Lisa Guisbond told reporters. "We just didn't want to see all restrictions taken off of the growth of the charter movement that we thought would undermine the quality of education for all of the existing schools that we have."

The Massachusetts Democratic Party, which voted to oppose Question 2, held a joint election night event with the No on 2 campaign at the Fairmont Copley Plaza Hotel. Reflecting a schism on the issue within the party, the pro-charter group Democrats for Education Reform held their own election night event in a smaller function room down the hall.

Democrats for Education Reform state director Liam Kerr said charters were a "prime case" of "something that's clearly good policy but it's bad politics."

"Change is hard," Kerr told the News Service. "Even when people know change is needed, even if you can demonstrate that a certain change works really well, it's incredibly hard to make change, so the people who might lose out in that change are going to be very, very opposed."

The Yes on 2 campaign, which gathered at the bar J.J. Foley's in the South End, released a statement saying it was "disappointed with tonight's result" and vowing that "the thousands of parents, teachers and students that have fueled this campaign will press on."

Charter schools are public schools that operate under five-year charters granted by the state and are managed by boards of trustees instead of local school committees. They have more freedom than traditional district schools to control their budgets, hire and fire teachers and staff and organize around a core curriculum or mission, according to the state Department of Elementary and Secondary Education.

More than 43,000 students were attending the state's 78 charter schools as of Oct. 1, about 4 percent of the total public school enrollment, according to the department. Another 32,600 students are on waiting lists for seats in charter schools, according to state data from June.

When lawmakers were unable over a span of years go agree on a path toward more charter schools, charter backers turned to the ballot in what promised to be an expensive campaign. Backers of Question 2 outraised their opponents $26 million to $15 million. The five committees supporting the question also outspent the opposition campaign, $24 million to $14 million.

The charter expansion fight was the most expensive of the four statewide ballot campaigns by a wide margin, beating out the next closest -- Question 4, to legalize adult use of marijuana -- by nearly $32 million in fundraising.

The Yes on 2 campaign counted seven state lawmakers among their supporters, including House Speaker Robert DeLeo and Rep. Alice Peisch, the House chair of the Education Committee. Opponents listed 117 legislators on their side, including Senate President Stan Rosenberg and Sen. Sonia Chang-Diaz, the Education Committee's Senate chair.

"The voters have spoken and the matter is resolved. It's time to shift our focus to 100% of the students in our public education system," Rosenberg said in a statement.