They are the oddest of odd couples. Mitt Romney is buttoned up and buttoned down, a by-the-numbers manager driven by data, logic and hard-headedness. John McCain is a freewheeling and unpredictable warrior, a visceral politician who relies on his gut and his instincts to make his way.

At this moment in the 2008 campaign, the two were sworn enemies, dueling in a nasty New Hampshire primary contest. On Wednesday, they found political communion on a stage in the Granite State. It is what happens to politicians.

Their appearance together was one more attempt by the Romney forces to say to a Republican electorate still hesitant to wrap its arms around the former Massachusetts governor: Victory is inevitable, so climb aboard.

Maybe that will be the case; the voters will decide. Little has been certain in the Republican race. Romney’s team has been preparing for a long struggle, if necessary, but Tuesday’s eight-vote victory over former senator Rick Santorum (Pa.) in the Iowa caucuses accelerates the timetable.

Four years ago, after his win in Iowa, Mike Huckabee handed to McCain, who was waiting in New Hampshire, the responsibility of blocking Romney’s path to the Republican nomination. The former Arkansas governor offered an exhortation that has been etched into the political history books. “Now it’s your turn to kick his butt,” he told McCain, according to an aide who overheard the phone call on caucus night.

The senator from Arizona obliged, dealing Romney a defeat days later that shattered his hopes of becoming the Republican nominee. But today Romney is in a position to do what no non-incumbent GOP presidential candidate in the modern era has done — win both Iowa and New Hampshire. And so on Wednesday, McCain gave Romney a pat on the back rather than a kick in the rear.

McCain, who had his first and last town hall meetings in New Hampshire in Peterborough, got a standing ovation when Romney introduced him here at their second event of the day. He cracked some of his trademark jokes, which New Hampshire audiences have heard scores of times. He joined Romney in answering questions from the crowd. He teased the candidate about his eight-vote victory in Iowa, calling him “Landslide Romney.”

McCain also implored the audience to use Tuesday’s primary to send Romney to South Carolina “with such momentum that he can’t be stopped.” Later he returned to that message, saying it is important to get to South Carolina with “a wind at our backs. Get this over with. Get the real contest going.”

For Romney, the McCain endorsement represents one more blessing from party elders and elected officials. He has been accumulating endorsements at a steady clip, carefully rolling them out for maximum impact. In New Hampshire, Romney already had the support of Sen. Kelly Ayotte, former governor John Sununu, former senator Judd Gregg, and a score of other elected officials.

But McCain is different. Few Republicans from outside the state enjoy more acclaim here than the senator. He won the Republican primary in both 2000 and 2008 and became a virtual resident of the state as his Straight Talk Express bus rolled from legion hall to high school gymnasium to local diner. Not for nothing is he sometimes called the president of New Hampshire.

As he was making his comeback in 2008, after his campaign broke apart six months before the primary here, McCain seemed to relish putting down Romney in debates. His sarcastic barbs sounded as personal as they were political.

When Romney said in one debate that the troop surge in Iraq “apparently” was working, McCain upbraided him. “The surge is working, sir,” he said. “It is working.” Romney protested: “That’s just what I said.” To which McCain responded scornfully: “No, not ‘apparently.’ It’s working.”

At the last debate before the 2008 primary here, McCain accused Romney of not telling the truth in his ads. “You can spend your whole fortune on these attack ads, but it still won’t be true,” he said. When the criticisms by McCain and others cut too close that night, a wounded Romney complained, “Is there a way to have this about issues and not about personal attacks?”

But when McCain wrapped up the nomination, something happened that surprised both the McCain and Romney camps. The relationship between the two men warmed considerably. Once his fate was clear, Romney didn’t linger in the race. He dropped out and with relative speed announced his support for his onetime rival. He told his staffers to do everything they could to help McCain in the general election.

Romney became the good soldier. He turned into one of McCain’s most loyal and energetic surrogates. He went wherever the campaign needed him, whenever he was needed. McCain, who appreciates loyalty, included Romney on his short list for a running mate, according to one of his advisers. When the economy collapsed in September 2008, McCain would have been better off with businessman Romney on the ticket than with Sarah Palin.

The two share something else. Both have been viewed with some suspicion by their party’s conservative base. Both adapted to changes in the GOP. Romney has been pushed to the right in this campaign because of the influence of the tea party. McCain went in the same direction in his Senate primary in 2010 to protect his seat.

Romney has said that, in his first campaign, he ran as a conservative alternative to McCain. In truth, neither man is well loved by conservatives. Many swallowed hard to accept McCain as their nominee in 2008. Some have vowed to resist a repeat with Romney. Wednesday’s endorsement will reinforce those feelings.

But for Romney, the endorsement is timely and valuable. It would be a stretch to say that politicians, as has been said of nations, have no permanent friends or allies, only permanent interests. But the scene in New Hampshire on Wednesday reminds us that political enemies can become allies, to the interest of both.