Republican John McCain and his opponent for the Senate nomination, JD Hayworth, seemed to be separated by a knife edge a few months ago. But Mr McCain won the primary election easily. What happened?
When Mr McCain walked into a party for volunteers at his Arizona headquarters on Monday night, he wore the same expression of bewildered surprise he always does at such events.
Arms stiffly outstretched - his war injuries have left him with such limited arm mobility he can't even comb his own hair - grasping hands, making his way through the supportive mob looking as though he really hadn't expected them to be there.
Mr McCain once told me that being sarcastic and willing to laugh at the same jokes over and over were the conditions of entry to the horseshoe-shaped lounges on the Straight Talk Express, the bus on which he spent most of the 2008 presidential campaign.
Back then, Mr McCain was the outsider. In mid-2007, his presidential campaign had crumbled under financial pressure and infighting, but somehow he'd staged a remarkable recovery.
He stuck to his guns on two of the most divisive issues around - immigration reform and the Iraq war - and managed to ride the rollicking, rickety Straight Talk to the Republican nomination.
He was labelled a maverick, the man who liked nothing more than to buck expectations, irritate his party and champion issues no sensible Republican would touch.
But in this week's Arizona Republican primary, Mr McCain was squarely the favourite - the establishment candidate.
He used his establishment might to devastating effect, burying his opponent in an avalanche of, at times brutal, campaign advertising. It cost $21m (£14m), more than he has spent in his previous Senate campaigns combined.
Many political analysts were left wondering if the old McCain - the one who thumbed his nose and cursed the bigwigs in his party, and partnered with Democrats Ted Kennedy to reform immigration, and Joe Lieberman to tackle global warming - had left the building entirely.
He seemed to be twisting himself into a pretzel to accommodate an unlikely ultra-conservative challenger, JD Hayworth, a right-wing talk radio host.
Over the course of the race Mr McCain was accused of tilting to the right to win votes. He was virtually silent on issues that had previously been signature ones for him - campaign finance reform and climate change.
And on the burning issue of the campaign - immigration reform - he abandoned his commitment to a path to citizenship for illegal immigrants in favour of tough talk about border security. "Complete the danged fence," he declared in a campaign ad.
In the end, the race wasn't even close. Mr McCain walloped Mr Hayworth by nearly 30 points. For the supporters filing into his victory party even before the polls closed, that seemed like a foregone conclusion.
But just a few short months ago, that was hardly the case.
In the early days of the McCain-Hayworth race, Mr McCain looked set to become the latest victim of a wave of anti-incumbent sentiment.
Mr Hayworth attacked him for not being a true conservative, hammering him in particular on immigration. Potential conservative primary voters responded, giving Mr Hayworth high numbers in early opinion polls.
But according to Mr McCain's press secretary Brooke Buchanan, Mr McCain had learned in recent years the value of defining an opponent's faults early. The campaign came out hard and strong.
For his part, Mr Hayworth was an easy target. He had been voted out of Congress in 2006 when his links to corrupt DC lobbyist Jack Abramoff were exposed in a major political scandal.
In a barrage of ads, Mr McCain effectively portrayed Mr Hayworth as a cartoonish buffoon, a shady huckster.
Mr McCain's media strategist Fred Davis - or Hollywood Fred, as the LA-based ad man is known in McCain world - says they didn't have to look hard for material.
They used an infomercial where Mr Hayworth appeared as a spokesman for an allegedly dodgy company promising "free money" grants from the government.
"There's so much more on JD we didn't use, and mainly it's because John didn't want us to," Mr Davis confides.
There were no regrets about running harsh campaign ads, Mr Davis says, because Mr Hayworth had been pummelling Mr McCain free on his radio programme for a year.
"But even in this campaign, John was hesitant to go negative," Mr Davis says. "He would prefer to win on his own merits, but I think maybe in '08, John learned that running on your own merits isn't sufficient."
Mr Hayworth has defended the adverts, saying he did not know about consumer complaints and a state attorney general's legal action. Critics said the firm lured consumers to a free seminar, then pressured them to spend money to access information readily available free online or in libraries.
But Mr Hayworth's considerable flaws as a candidate did not diminish his supporters' enthusiasm, nor their ardent desire to see Mr McCain bought down a notch or two.
Most of Mr Hayworth's supporters came from the Tea Party movement, a vocal but amorphous, staunchly conservative group who have wreaked havoc for traditional Republican candidates in places like Kentucky, Florida and Utah.
The Tea Party has made headlines around the country for months, with pundits fascinated by the spectacle of mostly older, mostly white, mostly angry conservative activists demanding that President Barack Obama "give their country back".
In Arizona, many Tea Party members consider Mr McCain an RINO (a Republican in Name Only), a phoney conservative. Hayworth supporters held a "RINO retirement party" for him just days before the primary.
"I don't think he's been honest. I don't think he's been conservative," says Carol Walters, an Arizona retiree and Tea Party supporter who has had a political awakening of sorts over the last year. JD Hayworth's campaign was the first campaign she had ever worked on.
"McCain reaches out across the aisle and wants to be friends with Obama. But we believe the Obama regime is very dangerous," Judy Hoelscher, another Tea Party supporter notes.
Their anger at Mr McCain is palpable, but it did not translate into political potency.
That's partly because their own candidate had problems, but partly because the movement itself hasn't cohered around a particular ideology or vision. They're all angry, but they're not all angry about the same thing.
For Tea Party supporter Diane Burnett, the problem is the economy and deficit spending. Vera Anderson worries about increased government regulation, and believes Mr Obama's policies are moving the country toward socialism.
Joel Berger is fed up with Mr McCain's attempts at bipartisanship, but immigration and amnesty for undocumented workers were the issues that pushed him away from Mr McCain for good.
"He's too centre-left," Mr Berger says. "I swallowed hard when I voted for McCain to be president. I just didn't want Obama."
In the end, the diversity and divergence of the Tea Party worked to Mr McCain's advantage - and an endorsement from his former running mate Sarah Palin helped divide and conquer.
"There is not one consistently powerful group called the Tea Party in America. There are states where it is very powerful, like Nevada. There are states where it's a tiny blip, like California," Mr Davis says.
And for now, that seems just fine with John McCain.