WASHINGTON — Senator Pat Roberts of Kansas announced Friday that he would not seek a fifth term in 2020, ending more than a half-century of service in Washington and setting off what will likely be another fractious Republican primary between the party’s warring establishment and conservative wings.

Standing before a shock of wheat at the Kansas Department of Agriculture’s headquarters in Manhattan, Kan., Mr. Roberts trumpeted the recent passage of the farm bill, recalled a career in Congress that began when he arrived on Capitol Hill as a congressional aide in 1967 and noted that he would leave Washington as the longest-serving lawmaker in state history. And, he noted, he never lost a race.

“I’m damn proud of that undefeated record,” said Mr. Roberts, 82, his voice choking with emotion at times.

But Mr. Roberts was nearly felled in his own primary in 2014, when he struggled to overcome the ascent of the Tea Party right and questions about his lack of a residence in Kansas. Mr. Roberts purchased a home of his own in Topeka in 2016, but he almost certainly would have faced another hard-fought primary had he run again.