Matt Bevin, the notoriously unpopular Republican governor of Kentucky, appears to have narrowly lost his bid for reelection in the deep-red state. And experts say the teachers who led statewide walkouts last year are the reason why.

Kentucky was one of several red states that saw mass protests last year by educators who were fed up with years of education budget cuts and low pay. In Kentucky, teachers called in sick to protest the passage of a bill overhauling the state’s public pension system, arguing it left educators with less generous retirement benefits and would further discourage new teachers from entering the profession.

While there were several big issues at stake in this gubernatorial election on Tuesday — including abortion access and Medicaid expansion— political experts say Bevin’s attacks on public education and his criticism of teachers likely sealed his fate and buoyed Democrat Andy Beshear, who led the vote by a margin of about 5,000 votes and declared victory Tuesday night, although Bevin has not yet conceded.

“[Bevin] committed a series of unforced errors in his battle with the teachers’ unions, using much more provocative language than necessary, much more combative language than necessary,” Stephen Voss, an associate professor of political science at the University of Kentucky, tells TIME.

Meanwhile, Beshear—who proposed a $2,000 pay raise for public school teachers, promised to raise their starting salary to $40,000 and pushed for student-loan forgiveness for educators—specifically thanked union members while declaring victory on Tuesday night. Bevin had criticized those plans as promises on which Beshear would be unable to deliver.

“Tonight, voters in Kentucky sent a message loud and clear for everyone to hear. It’s a message that says our elections don’t have to be about right versus left. They are still about right versus wrong,” Beshear said Tuesday. “That our values, and how we treat each other, is still more important than our party. That what unites us as Kentuckians is still stronger than any national divisions.”

For months, Bevin, who was elected in 2015, has been one of the most unpopular governors in the country, according to polling by Morning Consult. His disapproval rating increased sharply to 57% in early 2018, when the teacher walkouts took place in Kentucky. In the latest survey—conducted from July 1 through Sept. 30—53% of respondents disapproved of Bevin, and just 34% approved.

Paula Setser-Kissick was a registered Republican until August 2017, when she asked a question about teachers’ retirement eligibility during a Facebook Live Q&A with Bevin, who lashed out, saying, “If you happen to be a teacher who would walk out on your classroom in order to serve what’s in your own personal best interest at the expense of your children, you probably should retire.”

In response, Setser-Kissick — a digital learning coach for Fayette County Public Schools — registered as a Democrat, ran (unsuccessfully) for a state senate seat on an education-focused platform, and spent the last four months door-knocking for Beshear in Fayette County, where he ultimately won 65% of the vote.

“As the numbers show, our work made a difference, and we’re pretty proud of that,” says Setser-Kissick, 54, who hopes Beshear will solve the problems with the state’s pension plan, fully fund public education and limit the expansion of charter schools in the state.

During the past two years, Bevin has continued to insult teachers. In April 2018, he accused teachers of leaving children vulnerable to sexual assault and drug use during the statewide walkout. “I guarantee you somewhere in Kentucky today, a child was sexually assaulted that was left at home because there was nobody there to watch them,” he said. “Children were harmed — some physically, some sexually, some were introduced to drugs for the first time — because they were vulnerable and left alone.”

A year later, he suggested that teachers were to blame for the shooting of a 7-year-old girl, who was at home during another round of teacher “sick-outs” in March. She was reportedly being cared for by her legal guardian when she was accidentally shot by her 11-year-old brother.

And during a gubernatorial debate last month, Bevin doubled down once again, saying he regretted none of his previous comments about educators.

“I think it’s safe to say the sick-outs definitely played a part in his defeat. Let’s face it, they grabbed the public’s attention. When that happened, it focused the public’s attention on the bad behavior of both the governor and the legislature,” Setser-Kissick said. “I think Andy Beshear’s election reflected how Kentuckians were disgusted with such ugly attacks from an elected official.”

On the campaign trail, Beshear often pointed to Bevin’s teacher-related remarks as evidence that he was “unfit to govern.”

“A lot of people really just see Gov. Bevin as being very abrasive in his style,” says Thomas Matijasic, a history professor at Big Sandy Community and Technical College in Prestonsburg, Ky., and an expert in Kentucky politics. “He really, really insulted a lot of teachers. That might not seem to be a big deal in another state, but I think in Kentucky, where a far lower percentage of people have college degrees, teachers kind of form the core of the middle class, especially in rural areas, and I think there was a really negative impact. Even a lot of teachers who were registered Republicans disliked him.”

In his reelection bid, Bevin aligned himself closely with President Donald Trump, who hosted a rally for Bevin in Lexington, Ky., on the night before the election. His narrow loss in a state Trump won by 30 points in 2016 could now signal potential trouble for Trump’s path to reelection in 2020, especially because Bevin was the Republican candidate in Kentucky who tied himself closest to Trump in both political support and rhetorical style, says Voss. And while Bevin lost, Republicans won the other key state offices that were up for election in Kentucky.

“It’s not a general repudiation of the Republican Party,” Voss says of Bevin’s loss.

Bevin has not yet conceded, and he requested a recanvass of the election on Wednesday — a process in which county election officials check voting machines and absentee ballots to confirm all votes were counted and reported correctly.

But educators and their advocates have already celebrated the election outcome as a win for public education. “This victory demonstrates the power of educators and how the #RedforEd movement is reshaping the political landscape in Kentucky and across the nation,” National Education Association President Lily Eskelsen García said in a statement. “Educators are empowered and engaged like never before, and they made their presence felt in this election. They invested their shoe leather marching and going door to door. They spent their nights and weekends on the phone, calling voters.”

In Kentucky, even Republican educators say they’re looking forward to change, even if it comes in the form of a Democratic governor.

“Teachers don’t have summers off anymore, they don’t make a lot of money, and they’re certainly not respected by the governor who’s in there currently,” says Charles Clark, the assistant principal at Rowan County Middle School in Morehead, Ky. “I’m hoping that the governor-elect will be much more respectful. And based upon what he’s said and what his actions have been to this point, I think that will be the case.”

Clark, 41, ran in a Republican primary last year against incumbent state Rep. Jill York because he thought she wasn’t a strong enough advocate for public education. (York, who was endorsed in the primary by the Kentucky Education Association, defeated Clark, but later lost the general election to Democrat Kathy Hinkle.)

But Clark hopes that Bevin’s loss sends a message to politicians throughout Kentucky. A registered Republican, he says he did not vote for Bevin, even though he voted for other Republicans on the ballot.

“I hope they realize that how you treat people matters, that trying to degrade or downplay a profession… doesn’t work,” Clark says. “You can’t belittle the largest workforce in the state and expect to keep your office. When you’re supposed to be a representative democracy and you’re not representing your people, then you’re going to lose.”

Correction, Nov. 7

The original version of this story misstated details about former state Rep. Jill York’s election. She won the Republican primary in 2018, but she later lost the general election to Democrat Kathy Hinkle.

Get our Politics Newsletter. The headlines out of Washington never seem to slow. Subscribe to The D.C. Brief to make sense of what matters most. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

Write to Katie Reilly at Katie.Reilly@time.com.