As contenders for the presidency, the two had hammered each other for much of 2008 over their conflicting approaches to foreign policy, especially in Iraq. (He’d lose a war! He’d stay a hundred years!) Now, however, Mr. Obama said he wanted Mr. McCain’s advice, people in each camp briefed on the conversation said. What did he see on the trip? What did he learn?

It was just one step in a post-election courtship that historians say has few modern parallels, beginning with a private meeting in Mr. Obama’s transition office in Chicago just two weeks after the vote. On Monday night, Mr. McCain will be the guest of honor at a black-tie dinner celebrating Mr. Obama’s inauguration.

Over the last three months, Mr. Obama has quietly consulted Mr. McCain about many of the new administration’s potential nominees to top national security jobs and about other issues — in one case relaying back a contender’s answers to questions Mr. McCain had suggested.

Mr. McCain, meanwhile, has told colleagues “that many of these appointments he would have made himself,” said Senator Lindsey Graham, a South Carolina Republican and a close McCain friend.

Fred I. Greenstein, emeritus professor of politics at Princeton, said: “I don’t think there is a precedent for this. Sometimes there is bad blood, sometimes there is so-so blood, but rarely is there good blood.”

It is “trademark Obama,” Professor Greenstein said, noting that Mr. Obama’s impulse to win over even ideological opposites appeared to date at least to his friendships with conservatives on The Harvard Law Review when he was president.

For Mr. Obama, cooperation with his defeated opponent could also provide a useful ally in the Senate, where Mr. McCain has parlayed his national popularity and go-his-own-way reputation into a role as a pivotal dealmaker over the last eight years. But on the subject of Iraq, in particular, their collaboration could also raise questions among Mr. Obama’s liberal supporters, many of whom demonized Mr. McCain as a dangerouswarmonger because of his staunch opposition to a pullout.

This really could be a win-win situation for both Obama and McCain. Support from McCain will make it harder for the Republicans to successfully filibuster Democratic proposals backed by Obama, and helps Obama maintain his support among independents. While Obama probably could successfully ram through legislation on primarily partisan lines, he stands a greater chance of success if he can be seen as promoting bipartisan goals.

McCain can benefit too. John McCain was far more popular when he was seen as an independent as opposed to a partisan Republican. This could help rehabilitate his reputation, which was severely tarnished by the manner in which he conducted his campaign.

The 2008 campaign has been compared to the fictional Santos vs. Vinick campaign on the final season of The West Wing. Arnold Vinick was even modeled after the earlier John McCain (and Vinick didn’t have support for the Iraq war to undermine his reputation as a foreign policy expert). The West Wing ended with president-elect Matt Santos offering Arnold Vinick the post of Secretary of State. While Obama isn’t going that far (having given the post to another rival from the right), he is seeking out McCain’s advice far more than I would have predicted.