Across the country, Democrats made inroads in 2018 in suburban areas where they had long struggled. Near Minneapolis and St. Paul, two Republican congressmen lost their seats. Outside Chicago, Democrats took two congressional districts from Republicans and helped vote out Illinois’s Republican governor. And in suburban Orange County, Calif., one of the most famous Republican bastions of the 20th century, Democrats flipped four congressional seats.

In Kansas, Mr. Trump is by no means the only force stirring political turmoil. Sam Brownback, the Republican governor who resigned last year to become a United States ambassador, was deeply unpopular in the state after pushing a philosophy of fiscal austerity over several years; his approach to school funding and a tax-cutting plan that led to revenue shortfalls and service cuts angered many residents.

Last year’s Republican nominee for governor, Kris W. Kobach, who got his political start in Johnson County by serving on the Overland Park City Council, put off some suburban voters with his strident language about illegal immigration and his public embrace of Mr. Trump. (Mr. Kobach also raised eyebrows by showing up at a parade in Shawnee, in Johnson County, with a replica machine gun mounted on his Jeep.)

All the while, a longstanding split between conservative and moderate Republicans in Kansas has grown increasingly contentious.

“Conservatives, or the further-right faction of the Republican Party, have continued and continued and continued to try to force those of us of the moderate mind out of the party,” said State Senator Barbara Bollier, a retired anesthesiologist from Mission Hills who was the first of the four Johnson County legislators to announce that she was becoming a Democrat.

Along with Ms. Sykes, Ms. Clayton and Ms. Bollier, the other Kansas lawmaker who changed parties was State Representative Joy Koesten, who lost the Republican nomination to a conservative challenger in last year’s primary. Ms. Koesten announced that she was becoming a Democrat a few weeks before her term ended.

Some conservatives sounded untroubled by the exodus of moderate lawmakers, who had frequently voted with Democrats in the Legislature even before changing parties. Some conservatives even saw the switches as an opportunity, freeing the Republican Party to run more conservative candidates in those districts.