Sen. Pat Roberts (R-Kan.) told a crowd of supporters about the conversation with his opponent Greg Orman (I) Tuesday evening. (Elahe Izadi/The Washington Post)

Topeka, Kan. — Republican Sen. Pat Roberts entered to a battle anthem and took to the stage, a survivor.

“No, we weren’t dragged across the finish line -- we took the hill,” Roberts told the roaring crowd Tuesday night at the Capitol Plaza Hotel.

He had back-to-back brushes with political death following an ugly primary battle and aggressive general election campaign that didn’t begin in earnest until a month before Election Day.

He faced an uphill battle after winning an ugly primary race with just 48 percent of the vote.

Then the Democratic candidate, Chad Taylor, dropped out, leaving an opening for a millionaire businessman, independent Greg Orman. Roberts spent the better part of September trailing his challenger by as much as 10 points. He battled anti-incumbent fervor, a weak showing in the primary, criticism that he was out of touch with Kansas, late-game campaign staff and strategy shifts and an unusually chilly Kansas political scene for statewide Republicans, given a polarizing governor.

So the national party sent in reinforcements and replaced the people at the head of Roberts’s campaign. Sarah Palin, Ted Cruz, Rand Paul -- a galaxy of the GOP’s top stars -- trotted through what is often described as a flyover state. Bob Dole, on his tour of all 105 counties in Kansas, talked about his friend, Pat.

Outside groups poured in nearly $10 million to support Roberts and to oppose Orman. Other outside groups also spent nearly $6 million in negative ads against Roberts.

All of those efforts -- along with an aggressive campaign painting Orman as a lapdog for Washington Democrats -- helped Roberts pull out of a deficit and tie Orman in the final week of the campaign. Public polls showed the two remained in a statistical tie, with the Orman campaign feeling confident in recent days that they would end up pulling it off, with Kansas sending a non-Republican to the Senate for the first time since 1932.

When asked to reflect on the entirety of his political fight, Roberts chuckled on Monday, saying, “You mean the perfect storm?”

“It’s been a tough year for any incumbent,” Roberts said inside the Johnson County GOP headquarters on Monday. “The president has moved so far left and quite frankly, has made people so frustrated and upset that if you’ve been within the city limits of Washington, the federal limits of Washington, you’ve got a real challenge on your hands to explain to people you’ve been opposed to the Obama agenda all along. Then you try to highlight your past experiences, but people are so frustrated and angry that they’ve lost faith in their government.”

But Roberts also had the advantage of working within a traditional party infrastructure and the resources that come with that. Volunteers canvassed the state with mobile apps, county GOP offices all rallied behind him and phone banking continued non-stop. Roberts and his campaign crisscrossed the state relentlessly, speaking before farmers and pro-life activists and veterans.

The results surprised even them. The unofficial election results as of early Wednesday had Roberts beating Orman 53 to 43 percent -- a far bigger margin than any recent public poll had suggested.

“We were confident that our ground game would deliver, but we were expecting a much closer race,” said Roberts campaign strategist Chris LaCivita.

But their advantage on the ground was considerable. Orman had to build his ground game from scratch, hiring a polling firm and going after independents who don’t typically vote in midterms. The Orman campaign also relied heavily on volunteers, and on late outside spending that dumped nearly $1 million worth of negative ads against Roberts in the state.

The incumbent's major vulnerability stemmed from a perception that he was just out of touch with the state of Kansas. (Roberts doesn’t own a Kansas home he lives in, but rather rents a room in a donor’s house.) But voters who came out to see him on the trail consistently defended him on that front -- after all, they had sent him to Washington, they said. Roberts has served in Congress since the 1980s and was first elected to the Senate in 1996.

The campaign went after the conservative base and moderate Republicans, many of whom had strong negative feelings toward Republican Gov. Sam Brownback, with a two-fold message: voting against Pat Roberts would mean Republicans would be giving up the Senate. And Orman was a liberal, in a state where President Obama has an approval rating in the low 30s.

On the eve of the election, Roberts said the turning point came after “we kept hammering home the same points” about Orman and Senate control.

A political newcomer, Orman briefly flirted with a Senate run as a Democrat in 2008. Once the Washington operatives came in, attack ad after attack ad linked Orman with Senate Majority Leader Harry M. Reid (D-Nev.) and Obama. The Roberts campaign also attacked Orman for his ties to a former Goldman Sachs board member who was convicted of insider trading.

The Roberts fundraising operation outpaced that of Orman, who had sunk in his own money to fund nearly half of the $3.4 million raised by his campaign. But the outside groups dominated, spending nearly $17 million to dump mostly negative ads in the state.

The Roberts campaign never really sought to paint a new, rosy picture of the senator. A doom-and-gloom atmosphere hung over many stump speeches in the final days as Roberts and surrogates warned of the grave consequences should Kansas not reelect Roberts.

“Pat Roberts may not be perfect, but at least I know where he stands,” one campaign ad declared.

Orman, on the other hand, remained on-message about bucking gridlock and Washington itself, promising to be a voice of reason who would build bridges as he delivered  hope-and-change style speeches.

“You have turned this from a fledgling campaign into the number one threat to the status quo,” Orman told supporters at a rally on Sunday.

He also maintained a low profile in the campaign’s final weeks, visiting with small groups of voters in private settings and talking big-picture about Washington dysfunction. These appearances were so off the radar that even trackers had trouble finding him. Meanwhile, Roberts appeared at a string of high-profile rallies with big names. He also spoke on specific issues such as abortion and gun rights, and reminded farmers he stood in line to be the next agriculture committee chairman.

Even the tea party groups who had run attack ads against him ended up endorsing Roberts, driven by  a desire to retake the Senate.

“Tying [Orman] with Obama and Reid, it’s almost like a guilt thing: Kansas, don’t screw it up for the rest of the country,” said Clay Barker, Kansas State Republican Party executive director. “We need a Republican Senate.”

The final days in the campaign centered on the small stuff: whether Orman called Dole a clown, for instance, or whether the Roberts campaign had run an ad featuring a beloved football coach against his wishes.

It turned out that Orman remained an enigma for many. He had said he would caucus with whoever is in the clear majority -- but not if that majority came down to his decision. He also didn’t have clear positions on issues such as the Keystone XL pipeline and an assault-weapons ban. He did talk specifics on issues such as congressional reform.

“We've said this all along, we are relying on the independents and the intelligence of the Kansas voters, and I think that’s what’s going to count on Tuesday,” Orman said over the weekend. “They know Washington is broken, that we have to do something fundamentally different.”

On Tuesday, Kansas voters sent Pat Roberts back to Washington.