The view from Gemini 8, just 2 feet (0.6 m) from an Agena target vehicle, before achieving the first space docking on March 16, 1966.

Before Neil Armstrong and David Scott made history walking on the moon, they set another record on board one of NASA's most dramatic space missions, 50 years ago today (March 16).

The future first and seventh moonwalkers were paired up as the crew of Gemini 8, the first spaceflight to accomplish a docking between two vehicles in orbit.

"Flight, we are docked!" reported Armstrong, seconds after piloting the Gemini capsule to a linkup with an unmanned target vehicle. "It's really a smoothie." [How NASA's Gemini Spacecraft Worked (Infographic)]

But while the history-making docking went smoothly, what immediately followed almost ended in disaster for the two astronauts.

Agena docking target vehicle as seen from Gemini 8 before the mission’s historic docking on March 16, 1966. (Image credit: NASA)

Meeting with history

Armstrong and Scott launched atop a Titan II rocket from Cape Canaveral's Complex 19 on March 16, 1966 at 11:41 a.m. EDT (1641 GMT), about three hours after their target, an Agena upper stage, lifted off atop an Atlas booster from nearby Complex 14.

The Gemini 8 mission was planned to be three days long, during which Armstrong and Scott would rendezvous with the Agena-D target vehicle and perform four docking tests. The flight was to build upon the success of the Gemini 6 and Gemini 7 crews, who in December 1965 achieved the first rendezvous between two piloted space vehicles.

Scott was also slated to conduct an extra-vehicular activity (EVA), following the first American spacewalk by Gemini 4 astronaut Edward White in June 1965.

"We thought of it as being an absolutely super flight with great objectives," Armstrong recounted for "First Man," his 2005 authorized biography by historian James R. Hansen. Armstrong died in 2012 at the age of 82.

Six hours, five orbits and nine rendezvous maneuvers into the flight, at 5:14 p.m. EDT (2214 GMT), Armstrong closed the distance between the Gemini and Agena and docked.

"All was quiet as we felt first contact, then a firm clunk and capture as the docking latches joined the two vehicles," Scott wrote in "Two Sides of the Moon," his 2004 memoir with cosmonaut Alexei Leonov. "Docking seemed a piece of cake, as easy as parking a car in an open garage."

Danger after docking

Armstrong and Scott did not have much time to celebrate their success — or even grab a bite to eat — before Scott noticed that the "8-ball" on Armstrong's side of the capsule was showing their spacecraft was slowly rolling.

"Our first instinct was that the Agena, which had suffered problems in the past, was 'going wild,'" Scott recalled.

As they were docked, the crew had been using the target's engine to fly both craft so as to conserve the Gemini's fuel supply. Disabling the Agena control system seemed to halt the motion, but only briefly.

The roll picked up and increased in intensity, "to the point that we were starting to rotate on all three axes," described Scott.

Armstrong, following the earlier general advice of Mission Control, made the call to undock from the Agena. Pulling away sharply from the vehicle, Armstrong and Scott turned their attention to steadying their spacecraft.

"Immediately, it was obvious that the problem was not the Agena's," Armstrong explained. "It was ours."

Not that they were aware of it then, but one of Gemini 8's orbit attitude and maneuver system (OAMS) thrusters had suffered a short circuit and was stuck on firing. By the time the capsule moved into range to establish communications with the ground, the situation had grown dire.

End over (mission's) end

"We have serious problems here," Scott radioed to Mission Control. "We're tumbling end over end up here."

Gemini 8 was approaching, and possibly exceeding, a rate of one revolution per second. Inside, the astronauts were growing dizzy.

"I could tell when I looked above me to the controls for the rocket engine that things were getting blurry," Armstrong described. "I knew we were going to have to do something quickly to make sure that we could work on the problem without losing our vision or our consciousness."

Armstrong was left with just one option: disable the OAMS thrusters and change to using the re-entry control system.

"We both knew that if this didn't work, we were dead," Scott stated.

Reaching over his head, Armstrong toggled the switch to activate the thrusters at the front end of the Gemini. Soon, the spacecraft was back in his control.

A subsequent test confirmed it had been the no. 8 OAMS thruster that was the culprit. But even with that knowledge, the Gemini 8 mission was over.

"I knew what the mission rules were," Neil Armstrong said, "we had to land – and land at the next convenient opportunity."

The Gemini 8 crew of Neil Armstrong and David Scott are seen being recovered from the Pacific Ocean after splashing down from space in March 1966. (Image credit: NASA )

Lasting legacy

Gemini 8 re-entered the Earth's atmosphere on its seventh orbit and splashed down at 10:22 p.m. EDT (0322 GMT March 17) in the Pacific Ocean. Armstrong and Scott were tired but safe.

"We were disappointed we couldn't complete the mission, but the part we did have, and what we did experience, we wouldn't trade for anything," Armstrong wrote at the time.

Four months later, the Gemini 10 crew of John Young and Michael Collins used Gemini 8's Agena as a passive target and completed Armstrong's and Scott's mission objectives.

In the five decades since, more capsules have docked to other spacecraft, satellites have docked to other satellites and spacecraft have docked to space stations. The Soviet Union, the United States' competitor in the space race, accomplished its first uncrewed docking in October 1967. (The first Soviet crewed docking took place in January 1969 between Soyuz 4 and Soyuz 5).

The next spacecraft to dock is scheduled to do so Friday night (March 18), when Russia's Soyuz TMA-20M links up to the International Space Station to bring three new crew members for the orbiting outpost.

As for Armstrong and Scott, they each accomplished later dockings, piloting the ascent stage of their respective lunar modules to a connection with their Apollo 11 and Apollo 15 missions' command modules after walking on the moon.

Watch a vintage NASA film about Gemini 8 and the first space docking at collectSPACE.

Follow collectSPACE.com on Facebook and on Twitter at @collectSPACE. Copyright 2016 collectSPACE.com. All rights reserved.