"One small step for man, one giant leap for mankind" could have turned out dramatically different had it not been for astronaut Buzz Aldrin’s ingenuity in averting disaster with a simple felt-tip pen.

Following the Apollo 11 historic July 20, 1969, moonwalk, Aldrin and Neil Armstrong were preparing to return to command from their lunar module when they discovered that a 1-inch engine arm circuit breaker switch had broken off the instrument panel.

In his book, Magnificent Desolation: The Long Journey Home from the Moon, Aldrin recalls spotting something on the floor of the lunar module that didn’t belong there.

“I looked closer and jolted a bit,” he writes. “There on the dust on the floor on the right side of the cabin, lay a circuit breaker switch that had broken off.”

Wondering where the switch had come from, he looked at the rows of breakers on the instrument panel. Then he “gulped hard.”

Lunar Module pilot Buzz Aldrin on the spaceflight Apollo 11 in July 1969. SSPL/Getty Images

“The broken switch had snapped off from the engine-arm circuit breaker, the one vital breaker needed to send electrical power to the ascent engine that would lift Neil and me off the moon,” he writes.

READ MORE: 8 Little-Known Facts About the Moon Landing

Somehow, he or Armstrong must have accidentally bumped the switch in the cramped space with their cumbersome backpacks. “Regardless of how the circuit breaker switch had broken off, the circuit breaker had to be pushed back in again for the ascent engine to ignite to get us back home,” he writes.

The broken switch was reported to Mission Control, but after a fretful night trying to get some sleep, Houston had not figured out a solution the next morning.

“After examining it more closely, I thought that if I could find something in the LM to push into the circuit, it might hold,” Aldrin writes. “But since it was electrical, I decided not to put my finger in, or use anything that had metal on the end. I had a felt-tipped pen in the shoulder pocket of my suit that might do the job.

“After moving the countdown procedure up by a couple of hours in case it didn't work, I inserted the pen into the small opening where the circuit breaker switch should have been, and pushed it in; sure enough, the circuit breaker held. We were going to get off the moon, after all. To this day I still have the broken circuit breaker switch and the felt-tipped pen I used to ignite our engines.”

Buzz Aldrin and Neil Armstrong training in a mock-up lunar module in 1967 in preparation for the Apollo 11 mission to the moon. Ralph Morse/The LIFE Picture Collection/Getty Images

If the engine arm circuit breaker remained open, Armstrong and Aldrin likely would have been stuck, says NASA Chief Historian William Barry.

“Had the felt-tip pen not worked, I’m certain that Mission Control and the crew would have worked hard to find other ways to close the circuit so that the ascent engine could be fired,” he says. “But this was a serious situation—enough that on subsequent lunar modules a guard was installed over those circuit breakers to prevent a similar problem.”

READ MORE: Apollo 11 Moon Landing Timeline

Barry says that during the Apollo program, Mission Control and the astronauts ran thousands of simulations, and the simulation team was “quite devious” about coming up with problems for them to work through.

“I’m not aware that this specific scenario was simulated, but the in-depth systems knowledge learned in those hours in the simulators—and the techniques developed for astronauts and ground crews to work through problems—would have served them well if further work was needed to fix the broken ‘engine arm’ circuit breaker,” he says.

Many of those simulations, Barry notes, involved maneuvering the command module to complete the rendezvous in case of a problem with the lunar module ascent stage getting into the right orbit.

“As is typical of simulator training, the crews would have practiced the launch and docking maneuver many times—and usually while having to deal with some simulated failure,” he says. “Flying the actual mission was (usually) much easier than the dozens of times they would have practiced this particular maneuver in the simulator.”

But, Barry says, the command module couldn’t solve the problem if the lunar module wasn’t able to get off the surface. “So a failure of the ascent engine would have been a critical problem,” he says.