In Waterbury, Conn., where she taught high school history, Jahana Hayes always told her students to never become resigned to the challenging conditions they grew up in. Hayes, who was raised amid drug addiction and became a mother before she graduated high school, understood firsthand her students’ struggles with poverty and broken homes.

“I built my teaching career by telling my students you don’t get to complain here,” said Hayes, who in 2016 was named National Teacher of the Year. “If you see a problem in your community, you go and fix it.”

Earlier this year, when Rep. Elizabeth Esty resigned after it came to light that she had mishandled harassment allegations, Hayes decided to take her own advice. Prodded by Sen. Chris Murphy (D-Conn.), Hayes decided to run for Esty’s seat.

Tuesday, she defied expectations, besting veteran politician Mary Glassman, a former first selectman in Simsbury, Conn. Hayes won with 62 percent of the vote. The victory brought her one step closer to becoming Connecticut’s first black Democratic member of Congress and the first black Congresswoman from any New England state. She will face Manny Santos, the former mayor of Meriden, Conn., and winner of the Republican nomination, in November.

“People told me I had no chance and I had no business trying to do this,” Hayes said, speaking to supporters at her headquarters Tuesday night in Waterbury, Conn. “Tonight we proved them wrong.”

Hayes joins dozens of teachers inspired to run for office this year, often driven by their discontent with federal education policy and anger over persistent budget cuts. Educators ran for office in record numbers, buoyed by public support and momentum from teacher strikes. In Kentucky, a math teacher who campaigned on protecting public education and conservative values narrowly upset the state House majority floor leader in the GOP primary — even though the incumbent had the backing of Senate Majority Leader Mitch McConnell (R-Ky.).

Hayes is among a diverse slew of Democratic candidates — many of them minorities and women — who have defeated establishment candidates. In New York, Alexandria Ocasio-Cortez, a 28-year-old Latina, upset a 10-term congressman for the Democratic nomination. Demographic changes in Georgia could boost the prospects of Democrat Stacey Abrams, who would become the nation’s first black woman governor if she wins in November.

Education is figuring prominently in races for local and state government posts.

In Wisconsin, the state’s education chief, Tony Evers, won an eight-way race to become the Democratic gubernatorial nominee. Evers, who will face Gov. Scott Walker (R) in November, has attacked the governor for cutting education spending. The governor’s race in Arizona, where teachers won raises and additional school funding after a massive walkout, may be a referendum on the education policies of Gov. Doug Ducey (R).

Hayes has said she hopes to bring her classroom experience to the halls of Congress so that federal education policy is not so removed from what happens day-to-day in schools. She said lawmakers are too detached from what happens in the classroom, and often craft policies without understanding how they will trickle down to students.

“Every person in Congress should spend a day in a public school,” Hayes said earlier this year. “I don’t think they know what [education policy] looks like once it actually gets down to the classroom.”

Hayes’s approach to teaching her students — who often grew up in difficult circumstances — earned her praise and the National Teacher of the Year award in 2016. Her nominators spoke of her efforts to get students, who often faced difficult circumstances at home and in their communities, to perform community service.

In the end, Hayes said it was not just Murphy but her students who inspired her to run. She weighed her options while on a trip to California with some students, who had raised money to go on a trip to help build homes in the state for Habitat for Humanity.

“These are kids who have no reason to help anybody else because life has not been kind to them,” Hayes said in the spring. “I’m looking at these kids who are so excited . . . [and] they remind me of who we could be.”