WASHINGTON — On a Friday afternoon in mid-June, President Obama sat down with advisers in the Oval Office and learned that the F.B.I. planned to round up the largest ring of Russian sleeper agents since the cold war. After discussion about what the agents had done, the conversation turned to the fallout: what to do after the arrests? 
 
 In that moment was born a back-to-the-future plan that would play out four weeks later, a prisoner exchange with surreal and even cinematic overtones as Russian and American airplanes met on a sunny tarmac in the heart of Europe on Friday to trade agents and spies much as had been done during a more hostile era. 
 
 From the first time the president was told about the case on June 11 — 16 days before the Russian agents were actually arrested — a swap emerged as an option that could resolve a potentially volatile situation without undercutting Mr. Obama’s effort to rebuild Russian-American relations. The Russian spy ring would be broken, the Americans would secure the release of four Russian prisoners and both sides could then put the episode behind them. 
 
 Administration officials said Friday that the arrests were not made for the purpose of making a deal and that no decision about a swap was made until after the agents were in custody. But they described a fast-moving sequence of events after the arrests in which both sides scrambled to reach an agreement, even to the point of Russian officials’ offering money and other benefits to encourage one of their sleeper agents to consider the deal. 
 
 The officials described the episode as perhaps the most serious test yet of the new relationship, as well as a sign of its enduring complexity. 
 
 By Friday afternoon, the 10 Russian sleeper agents arrested in American cities and suburbs were flown back to Moscow, while four men released from Russian prisons were taken from the transfer point in Vienna to London. Two of them, Igor V. Sutyagin and Sergei Skripal, got off there, and the remaining two, Aleksandr Zaporozhsky and Gennadi Vasilenko, flew on to Dulles International Airport just outside Washington. The children of the sleeper agents all left with their parents or were preparing to join them, officials said. 
 
 The lawyer for one of the freed Russians called it “a historic moment” that she had long suspected would come. “It has to do with the relations between the two countries, and with political games going on at the top,” said the lawyer, Maria A. Veselova, who represented Mr. Zaporozhsky, a former Russian intelligence agent. “It is always connected with these chess games.” 
 
 The games have been played for years, and this one was no exception. The F.B.I. had been monitoring the Russian sleeper agents as far back as a decade, and along with the C.I.A. and the Justice Department, gave the first detailed briefing to the White House in February, American officials said. 
 
 By late May and early June, counterespionage officials grew concerned that several of the agents were planning to leave the country this summer and concluded that they would have to arrest them. 
 
 At the Southern District of New York, prosecutors pulled out files on the case and completed a 37-page complaint, describing the agents’ activities, the sophisticated intelligence technology they used, and the F.B.I.’s extensive and long-term surveillance in unusual detail. A version of the document sat for years in a classified safe in New York, updated and rewritten by Michael Farbiarz, the lead prosecutor, as new evidence was developed, ready to be used whenever necessary. 
 
 “The value of a complaint like that is that you show immediately that you’ve got them dead to rights,” said David S. Kris, assistant attorney general for national security. “It showed the defendants and the Russians that we’ve got the goods. We’re not bluffing here. We’ve had you under investigation for quite a while. We’ve been in your houses, we’ve done surveillance and we have got plenty. That obviously helps things move quickly.” 
 
 Before they moved on the arrests, though, they had to tell the president. Mr. Obama was preparing to host the Russian president, Dmitri A. Medvedev, at the White House on June 24, so any arrests were bound to be politically explosive. The president’s homeland security and counterterrorism adviser, John Brennan, led the June 11 Oval Office briefing, at which officials described who the agents were, what would be in the complaint and what they would be charged with. 
 
 “There was a full discussion about what was going to happen on the day after,” said one senior White House official, who spoke on the condition of anonymity to describe internal discussions. Mr. Obama then had a meeting on the case with his National Security Council on June 18, just six days before Mr. Medvedev’s visit. 
 
 The visit went off without any discussion of the case, White House officials said, but three days later, the F.B.I. arrested 10 agents, a sweep that made headlines as a relic of the cold war. The administration moved quickly to keep the arrests from provoking the traditional volley of angry denunciations and retaliations, contacting Moscow to indicate the depth of the evidence and its willingness to resolve the situation. 
 
 Russian officials responded by removing an initial statement calling the charges “baseless” from the Foreign Ministry Web site and issuing a new one acknowledging that some of those arrested were Russian citizens. American officials were struck by the tempered remarks by Prime Minister Vladimir V. Putin, a former K.G.B. colonel, during a meeting with former President Bill Clinton. ||||| U.S. and Russian flights involved in a 14-person spy swap landed briefly in Vienna, apparently exchanged agents, then took off again in the largest such diplomatic dance since the Cold War. 
 
 In a carefully scripted exchange, the two planes arrived within minutes of each other Friday, parked nose-to-tail at a remote section on the tarmac, then spent about an hour and a half there before departing just as quickly. 
 
 The swap apparently completed, a Russian Emergencies Ministry Yakovlvev Yak-42 plane left Vienna reportedly carrying 10 agents deported from the U.S. Minutes later, a maroon-and-white Boeing 767-200 that brought those agents in from New York took off, apparently with four Russians who had confessed to spying for the West. 
 
 No information was immediately available as to the planes' destinations. But the Russian flight was thought to heading for Moscow, while the U.S. charter was likely flying to London. 
 
 Igor Sutyagin, an arms control researcher convicted of spying for the United States, had told relatives of the spy swap while still in prison and said he was being sent to Vienna and then onto London. 
 
 Vienna has long been involved in such Cold War-like machinations, the capital of neutral Austria being a preferred place to work on treaties and agreements meant to reduce U.S.-Soviet tensions. 
 
 Both countries won admissions of crimes from the subjects of the exchange _ guilty pleas in the U.S. and signed confessions in Russia. 
 
 In exchange for the 10 Russian agents, the U.S. won freedom for and access to two former Russian intelligence colonels who had been convicted in their home country of compromising dozens of valuable Soviet-era and Russian agents operating in the West. Two others also convicted of betraying Moscow were wrapped into the deal. 
 
 One ex-colonel, Alexander Zaporozhsky, may have exposed information leading to the capture of Robert Hanssen and Aldrich Ames, two of the most damaging spies ever caught in the U.S. 
 
 U.S. officials said some of those freed by Russia were ailing, and cited humanitarian concerns in part for arranging the swap in such a hurry. They said no substantial benefit to national security was seen from keeping the captured agents in prison for years. Former intelligence operatives agreed. 
 
 The 10 Russian agents arrested in the U.S. had tried to blend into American suburbia but been under watch for up to a decade by the FBI. Their access to top U.S. national security secrets appeared spotty at best, although the extent of what they knew and passed on is not publicly known. 
 
 The lawyer for one of them, Vicky Pelaez, said the Russian government offered her $2,000 a month for life, housing and help with her children _ rather than the years behind bars she could have faced in the U.S. if she had not agreed to the deal. 
 
 In an elaborate round of dealmaking, U.S. officials met Monday in Russia with the convicted spies and offered them a chance for freedom if they left their homeland. Russian officials in the U.S. held similar meetings with the agents captured by the FBI. 
 
 On Thursday, Russian President Dmitry Medvedev signed a decree pardoning the four after officials forced them to sign confessions. 
 
 The Kremlin identified the four as Zaporozhsky, Sutyagin, Gennady Vasilenko and Sergei Skripal. 
 
 Zaporozhsky, a former colonel in the Russian Foreign Intelligence Service, sentenced in 2003 to 18 years in prison for espionage on behalf of the United States. He was convicted on charges of passing secret information about Russian agents working undercover in the United States and about American sources working for Russian intelligence. 
 
 Skripal, a former colonel in the Russian military intelligence, was found guilty of passing state secrets to Britain and sentenced to 13 years in prison in 2006. He was accused of revealing the names of several dozen Russian agents working in Europe. 
 
 Sutyagin, a military analyst, asserts his innocence despite the confession. He worked with the U.S.A. and Canada Institute, a respected Moscow-based think-tank, before being sentenced to 15 years in 2004 on charges of passing information on nuclear submarines and other weapons to a British company that Russia claimed was a CIA cover. Sutyagin says the information he provided was available from open sources. 
 
 Gennady Vasilenko, a former KGB officer employed as a security officer by Russia's NTV television, was sentenced in 2006 to three years in prison on murky charges of illegal weapons possession and resistance to authorities. It was not exactly clear why he was involved in the spy swap. 
 
 ___ 
 
 Associated Press writers George Jahn in Vienna, David Nowak in Moscow and Danica Kirka in London, Larry Neumeister, Tom Hays and David B. Caruso in New York and Calvin Woodward in Washington contributed to this report.
– The spies have been swapped, the New York Times reports. US and Russian planes carrying their respective undercover agents landed briefly at a Vienna airport, did a passenger switch, and flew back to their homelands. In return for handing over the 10, the US got four people who had been serving time in Russia. They include arms control researcher Igor Sutyagin. The AP says the handoff was straight out of a Cold War handbook. The two planes landed within minutes of each other in a remote part of the airport and ended up nose to tail. They were there about 90 minutes before taking off. “This action was carried out in the overall context of improved Russian-American relations," says the Russian Foreign Ministry.