For the past six years, Travis Brenda voted like nearly everyone else in his part of rural central Kentucky. In 2012, 2014 and 2016, he helped send Jonathan Shell to the State House of Representatives, re-electing him again and again as he eventually rose to House majority leader.

He watched as Mr. Shell and other politicians failed to add meaningful dollars to public education, embraced charter schools and cut state services. Then over a few hours on March 29, Mr. Shell helped introduce and pass a surprise 291-page plan to significantly overhaul the state’s struggling pension system that the governor later signed into law.

Suddenly, years of bubbling anger among state employees and teachers in Kentucky erupted in protests and chants at the Capitol, fueling a sustained backlash that helped lift Mr. Brenda to an unlikely victory on Tuesday night. Mr. Brenda, a first-time candidate and a math teacher, knocked off Mr. Shell, who had both name recognition and fund-raising prowess, by 123 votes in the Republican primary for House District 71.

“We trust those we elected to do the right thing,” Mr. Brenda, 43, who teaches at Rockcastle County High School in Mount Vernon, Ky., said in an interview on Wednesday morning. “What we are seeing is that they are not doing the right thing.”