Even today, 30 years after the fact, the Cuban missile crisis ranks as the climactic moment of the cold war-a superpower morality play in which courage and candor triumphed and low cunning and dark purposes were defeated. The missile crisis pitted a popular and charismatic American president, John F. Kennedy, against a wily and bellicose Soviet leader, Nikita Sergeyevich Khrushchev. It involved-it was fundamentally about-the most lethal weapons of mass destruction then known, and it was played out in full view of millions upon millions of ordinary citizens the world over. Most of all, it ended happily-which is to say, without nuclear war.

Few who lived through that period, Oct. 14-28, 1962, will ever forget the drama that unfolded day by day. There was Kennedy's somber television speech to the nation on Oct. 22. Two days later, on Oct. 24, came news that Soviet ships approaching the U.S. Navy's mid-Atlantic quarantine line had stopped dead in the water. "We're eyeball to eyeball," Secretary of State Dean Rusk said laconically, "and I think the other fellow just blinked." On the 25th, Adlai Stevenson stunned the United Nations and flummoxed Soviet Ambassador Valerian Zorin with dramatic U-2 photographs of the missiles themselves. Finally, on Oct. 28, there was Radio Moscow's announcement that Khrushchev had ordered the missiles removed from Cuba. Americans everywhere stood and cheered.

But the newsreel version of the Cuban missile crisis is distorted-a cartoon rendition of a complex series of actions, some intended and some not, that took the world much closer to war than most Americans ever knew. Kennedy, to be sure, conducted himself with distinction throughout the crisis, and the whole episode is rightly studied as a textbook case of presidential leadership in a time of acute international tension. But the real history of the missile crisis has been coming out bit by bit for years, partly from Soviet sources and now from secret U.S. documents released by the CIA. Taken as a whole, that history is far less reassuring than the more familiar version. It is a story of blunder, miscalculation and dumb luck. It is also the story of remarkable dedication and competence within the U.S. intelligence community and the stunning contribution of an almost forgotten Soviet traitor.

The missile crisis had its origins in the Bay of Pigs invasion and the superpower arms race. The Bay of Pigs debacle, 20 months earlier, convinced Khrushchev that Kennedy would buckle under pressure, and it may have led him to believe Cuba needed Soviet protection against another U.S. invasion. But his essential motive for the missile gambit was strategic. Despite Khrushchev's bluster, both sides knew the Soviet Union was far behind the United States in missiles, bombers and deliverable nuclear warheads. U.S. analysts now believe the Soviets had no more than 44 operational intercontinental missiles and 155 long-range bombers in 1962--while the United States had 156 ICBMs, 144 sub-launched Polaris missiles and 1,300 strategic bombers.

Deploying medium-range missiles in Cuba gave Soviet forces a significant increase in the number of warheads that could reach the United States-though it is unlikely that Khrushchev had nuclear war in mind. Khrushchev was a believer in atomic diplomacy. Obsessed by the Soviet Union's strategic inferiority, he " was looking for any way to talk to the Americans equally," says Aleksandr Alekseyev, who was Soviet ambassador to Cuba during the crisis. The Cuban gamble was a quick and easy way to redress the nuclear balance, and the Castro regime was more than willing. In early May, Alekseyev was summoned to the Kremlin and briefed on Khrushchev's plan. If the deployment was kept secret until after the U.S. elections in November, Khrushchev said, Kennedy would not risk war to force them out. No one asked whether the Americans might find other ways to force a Soviet retreat.

Almost no one in Washington believed that Khrushchev would try it. True, the CIA had thousands of alarming reports of Soviet missile activity in Cuba--but these reports, most of which came from Cuban refugees arriving in Miami, were invariably wrong. True, the CIA knew the Soviets had begun a considerable military buildup to defend the Castro government and that Soviet "technicians" were building a chain of SAM-2 missile batteries from one end of the island to the other. But the SAM-2 was an antiaircraft missile: it didn't carry a nuclear warhead and it couldn't even reach Key West. Consequently, the agency took a skeptical view of the many missile sightings contained in the refugee reports: to a civilian, a 35-foot-long SAM would look like a monster missile.

In a national intelligence estimate prepared for Kennedy on Aug. 1, the CIA and other U.S. intelligence agencies maintained that the Soviet buildup on Cuba would almost certainly be limited to defensive weapons. That judgment, appallingly wrong, was reaffirmed in a second special estimate on Sept. 19-the day after the CIA received a top-secret report from an agent inside Cuba identifying the precise area, about 50 miles southwest of Havana, where the Soviets were building a base for their SS-4 ballistic missiles. The agent's report, written in invisible ink and sent to a mail drop outside Cuba, has now been released by the CIA. It warned that Soviet troops had blocked off a large area of Pinar del Rio province around the town of San Cristobal, and that very secret work, probably involving missiles, was taking place on the finca (ranch) of a Dr. Cortina. CIA headquarters skeptically noted that "it is doubtful that ground forces could effectively control ... a zone as large as the one cited above."

But they had-and in mid-October, the first SS-4s arrived at San Cristobal. By that point, CIA Director John McCone had won a narrow victory in his clash with Rusk on the need to send U-2 spy planes to reconnoiter the Soviet buildup. Almost alone in the U.S. intelligence community, McCone was certain Khrushchev would send offensive missiles to Cuba: his reasoning was that the SAM-2 network was a sign the Soviets were up to something big. Rusk, equally adamant, was worried that the U-2s would be shot down by the SAMs, just as Francis Gary Powers's plane had been shot down over the Soviet Union in 1960. This impasse, compounded by rainy weather over Cuba, prevented U.S. reconnaissance for more than a month-but on Oct. 14, an air force U-2 flew directly over San Cristobal at 72,500 feet with its camera rolling.

The San Cristobal imagery was stunning: it showed SS-4s at two different sites in a hilly, wooded area outside town. Those rotten bastards, thought Vincent DiRenzo, the CIA photo interpreter who made the call. DiRenzo told his boss, Dino Brugioni, and the photo team checked its conclusions against "the black book." The black book contained the CIA's best information on Soviet strategic weapons. Some of it was fragmentary and some of it was wrong--but the book was dead accurate about the SS-4. It said the SS-4 had a range of 1,020 nautical miles--enough to reach Washington from San Cristobal--and that it carried a one-or three-megaton nuclear warhead. The book contained remarkably specific information on SS-4 launching operations and a detailed perspective drawing of a typical launch site that showed the missile erector, the control cabling and the missile-ready tents. Everything matched.

This mother lode of Soviet missile secrets was code-named "Ironbark" and was arguably the most spectacular Western espionage coup of the cold war. Ironbark was the work of one man, an embittered Soviet colonel named Oleg Penkovsky--a senior agent in the GRU, Soviet military intelligence, and the son-in-law of a Soviet Army marshal. His story has now been retold by Jerrold L. Schecter and Peter S. Deriabin in "The Spy Who Saved the World," a book that relies heavily on CIA sources. Penkovsky was arrested on Oct. 22 and executed in 1963. But he had already provided the West with invaluable political and strategic intelligence from the top echelons of the Soviet military hierarchy. The SS-4 data, microfilmed from the manual of a Soviet officers' school, was crucial. "It was possible to look at the diagram and tell just how far along they were and how soon the missiles would be ready to fire," says former CIA director Richard Helms. "This was extremely important in the management of the crisis."

The U-2 imagery galvanized the Kennedy administration. Photo reconnaissance was stepped up: navy and air force jets, screaming over Cuba at 300 to 500 feet, provided a day-by-day record of the Soviets' frenzied efforts to prepare the missile sites. How soon would they be ready? Kennedy wanted to know. Five to six days, said CIA missile expert Albert Wheelon. Are you sure? JFK demanded. You bet your ass, Wheelon thought--then, remembering where he was, said, "Yes, sir." More SS-4s were found at Sagua La Grande, 150 miles east of Havana. Two new sites, one just west of Havana and one 185 miles to the east, were identified as launch areas for an entirely different missile, the SS-5. The SS-5 carried a larger warhead and had a range of 2,200 nautical miles-enough to reach most major cities in the continental United States. (The SS-5s, on Soviet ships that turned back when the United States imposed its naval quarantine, never reached Cuba.)

The combination of Penkovsky's material and intensive photo reconnaissance gave Kennedy two priceless advantages in the crisis: certainty and time. Time was crucial: it gave diplomacy a chance. Were the missiles being prepared for a Soviet first strike? It seemed unlikely, but no one knew for sure. The SS-5s in particular posed a threat to U.S.-based strategic bombers and missiles, and the Joint Chiefs of Staff were alarmed. The chiefs debated an array of military options ranging from bombing Cuba (OPLAN 312), 18 days of bombing followed by invasion (OPLAN 314) and five days of bombing followed by invasion (OPLAN 316, a so-called quick-reaction variant). Administration officials also discussed surgical strikes on the missiles, but the JCS thought that wouldn't work.

Kennedy and his top advisers--the "ExComm," or executive committee of the National Security Council-weighed the options and settled on a public warning to Khrushchev backed by a naval quarantine of Cuba. The blockade was firm action that stopped short of bombing or invasion. Throughout the crisis, Kennedy fended off pressure to use military force; his calm restraint was the measure of true leadership. The CIA, meanwhile, was desperately trying to figure out if the SS-4s had nuclear warheads. Field agents used neutron detectors, a device like a Geiger counter, to check for radiation coming from Soviet planes and ships en route to Cuba. Dino Brugioni, now retired from the CIA, has written an ambitious history of the crisis (" Eyeball to Eyeball: The Inside Story of the Cuban Missile Crisis"). He says the warheads were already on the sites-in specially equipped vans the photo experts had overlooked. The SS-4s and their nuclear payloads could be ready for launch within hours.

Kennedy waited four days for Khrushchev to respond. In Cuba, Soviet troops finished work on the SS4 sites around San Cristobal and Sagua La Grande; in Washington, the Joint Chiefs of Staff pressed for tougher action--probably OPLAN 316, the quick-reaction plan. But Moscow was silent--and even now, former Soviet officials give sharply contradictory accounts of Khrushchev's decision process. Oleg Troyanovsky, a career Soviet diplomat who in 1962 was Khrushchev's translator, says Khrushchev did not seem alarmed by Kennedy's Oct. 22 speech or the U.S. quarantine. One of the six Soviet deputy commanders in Cuba, Gen. Leonid Garbuz, says Khrushchev gave orders to Soviet forces on the island to resist any American attack on Oct. 22, Oct. 25 and again-"categorically"-- on Oct. 27. Garbuz, interviewed in Moscow by NEWSWEEK'S Dorinda Elliott, also says Khrushchev was emphatic that no nuclear weapons could be used.

Garbuz's account may shed new light on Khrushchev's thinking as the crisis approached its finale. Garbuz confirms that Khrushchev did not order the SAM launch that shot down an air force U-2 on Oct. 27; a Soviet commander in Cuba did that. But Khrushchev's repeated orders to his commanders to resist an American attack suggest that he was prepared to risk a shooting war as late as Oct. 27.

Kennedy was still maneuvering to resolve the crisis peacefully. Khrushchev on Oct. 26 had sent a long, impassioned letter that seemed to promise the missiles' withdrawal. On Oct. 27, however, Khrushchev sent a second letter demanding that Kennedy remove U.S. Jupiter missiles from Turkey in exchange for the SS-4s. The U-2 shoot-down that same day seemed to underscore this new demand with the threat of further hostilities. Transcripts of the ExComm's deliberations show that many of Kennedy's advisers expected rapid escalation. The Joint Chiefs, unwilling to tolerate further attacks on U.S. reconnaissance planes, pushed for prompt approval of OPLAN 316.

Still, Kennedy played for time. He sent Robert Kennedy to see Anatoly Dobrynin, the Soviet ambassador in Washington, with a last message to Khrushchev. While accounts differ, the message seems to have been half stick and half carrot. The Jupiters would be withdrawn, so long as this concession was never linked publicly to the SS-4s-but all hell would break loose over Cuba unless Khrushchev replied within 24 hours. Again, the American side waited--and on Sunday, after a meeting with his inner circle at a government dacha outside Moscow, Khrushchev accepted the deal. The crisis was over. But the cold war and the arms race continued for 27 more years--and the lesson for presidents, looking back at the harrowing days of October '62, is to ensure that we never come so close to the brink again.