Apollo 11 astronauts planted a flag on the moon on July 20, 1969. NASA

NASA's Apollo 11 mission sent three astronauts to the moon exactly 50 years ago, in July 1969. Two of them landed on the moon's surface and they all returned home safely.

But NASA knew the mission was very risky, so the White House prepared remarks in case the astronauts died.

President Nixon's speechwriter, William Safire, drafted the backup speech , titled "In Event of Moon Disaster," which was publicly released 30 years later.

In the years since Apollo 11, we've learned about ways the astronauts could have died several times during the mission.

Visit Business Insider's homepage for more stories.

Fifty years ago, on July 20, 1969, Neil Armstrong and Buzz Aldrin stepped off a tiny spacecraft and onto the surface of the moon as the world watched live.

Armstrong, Aldrin, and Michael Collins - who remained in orbit around the moon- had blasted into space atop a giant Saturn V rocket four days prior, on July 16, 1969. The three men safely splashed down in the Pacific Ocean on July 24.

Although the plucky astronaut crew made the mission look easy, NASA knew better: This was easily the most perilous voyage in history.

Read More: The Apollo moon program's Mission Control Center has been restored and opened to the public. Check out the 1969 time capsule.

So, shortly before launch, Apollo 8 astronaut and White House liaison Frank Borman called President Nixon's speechwriter, William Safire.

A colorized image of President Richard Nixon. Getty Images/Algorithmia

"You'll want to consider an alternative posture for the President in the event of mishaps," Borman told Safire, according to an NBC "Meet The Press" interview with Safire on July 18, 1999.

At first, Safire didn't understand what Borman meant - he told NBC that it sounded like "gobbledygook" - but Borman quickly clarified.

"I can hear [Borman] now: 'Like what to do for the widows,'" Safire said.

In short, Borman wanted a backup speech ready in case the Apollo 11 crew died.

NASA anticipated that the highest risk of death for Armstrong and Aldrin would come during their launch off the moon's surface on July 21, when they would return to lunar orbit and meet up with Collins inside the Command Module.

"But if they couldn't [launch], and there was a good risk that they couldn't, then they would have to be abandoned on the moon, left to die there," Safire told NBC's Tim Russert.

"Mission Control would then have to - to use their euphemism - 'close down communication,' and the men would have to either starve to death or commit suicide," Safire said. "And so we prepared for that with a speech that I wrote, and the President was ready to give that."

Two days into the moon mission - on July 18, 1969 - Safire sent a draft of his "In Event of Moon Disaster" speech to H.R. "Bob" Haldeman, Nixon's chief of staff.

Here's the full speech, which first came to light in 1999:

Fate has ordained that the men who went to the moon to explore in peace will stay on the moon to rest in peace. These brave men, Neil Armstrong and Edwin Aldrin, know that there is no hope for their recovery. But they also know that there is hope for mankind in their sacrifice. These two men are laying down their lives in mankind's most noble goal: the search for truth and understanding. They will be mourned by their families and friends; they will be mourned by their nation; they will be mourned by the people of the world; they will be mourned by a Mother Earth that dared send two of her sons into the unknown. In their exploration, they stirred the people of the world to feel as one; in their sacrifice, they bind more tightly the brotherhood of man. In ancient days, men looked at stars and saw their heroes in the constellations. In modern times, we do much the same, but our heroes are epic men of flesh and blood. Others will follow, and surely find their way home. Man's search will not be denied. But these men were the first, and they will remain the foremost in our hearts. For every human being who looks up at the moon in the nights to come will know that there is some corner of another world that is forever mankind.

You can see pictures of the original typewritten remarks at the US National Archives site.

Near misses could have ended Apollo 11 in tragedy

If several risky moments had gone another way, Nixon may have had to use that speech.

Apollo 11 astronauts quarantined in their "Hornet 3" trailer meet then-President Richard Nixon. NASA

One such close call came as Armstrong and Aldrin landed on the moon: They overshot their landing site by 4 miles, and the new spot was dangerously rocky. Armstrong took control of the spacecraft and directed it to safer ground, all while alarms blared as the flight computer malfunctioned. They landed with just 45 seconds' worth of fuel left in the landing tank.

Then, during their 21 hours on the moon's surface, Aldrin discovered that a critical circuit breaker on the lunar module was broken.

"You get ready to land, you push that thing in … You get on the surface of the moon, you pull that out. If you wanna come home, you gotta push that thing in again, but it's broken off," Aldrin said at an event celebrating the moon-landing anniversary at The Explorers Club in New York City , according to Space.com.

"If they couldn't get off, they were dead men, and I was getting home by myself," Collins added.

Luckily, Aldrin jerry-rigged the breaker by pushing the button in using a pen.

Yet another near miss that put the astronauts at risk was revealed only in recent weeks: As the Apollo 11 crew reentered Earth's atmosphere and prepared to land in the Pacific Ocean, a discarded service module from their spaceship didn't jettison away from from the vehicle carrying the astronauts as planned. That put them at risk of a crash.

"If things had gone bad, we could have lost the Apollo 11 crew," Gary Johnson, an Apollo program engineer, told Nancy Atkinson, the author of a book on the subject. "We were lucky."

This post has been updated. It was originally published on July 23, 2017.

NOW WATCH: Popular Videos from Insider Inc.