Alexei Leonov, a Soviet cosmonaut who in 1965 became the first person to walk in space and who was scheduled to walk on the moon before the Soviet Union abandoned its efforts for a manned lunar landing, died Oct. 11 in Moscow. He was 85.

The Russian space agency, Roscosmos, announced his death but did not cite a cause.

Mr. Leonov, a Soviet air force officer, was chosen in 1959 as part of his country’s inaugural class of astronauts — known as cosmonauts in the old Soviet Union. At the time, the Soviets were leading the space race, a symbolic and strategic battle for technological superiority during the Cold War.

In 1957, the Soviet Union launched Sputnik, the first satellite to orbit Earth. In April 1961, cosmonaut Yuri Gagarin — a close friend of Mr. Leonov’s — became the first person launched into space.

As the U.S. space program tried to catch up, with flights by Alan B. Shepard Jr. and John Glenn, the Soviets sought new ways to maintain their early edge. Mr. Leonov began training for his spacewalk in 1963.

He underwent a rigorous program of swimming and running and was subjected to long periods of weightlessness. A special suit and helmet were made to withstand the extreme conditions in space.

As perilous as early space travel was, it seemed doubly dangerous for a human being to “walk” — or, more precisely, to float — outside the safety of the capsule. On March 18, 1965, Mr. Leonov took that step.

He left the capsule through a hatch, leaving a fellow cosmonaut, Pavel Belyayev, to pilot the ship. Mr. Leonov entered an airtight chamber called an air lock and inhaled pure oxygen for almost an hour to reduce the level of nitrogen in his blood, as a means of preventing decompression sickness, or the bends.

Notable deaths in 2019: Elijah Cummings, Cokie Roberts, Toni Morrison and others we have lost this year

Don Imus | Don Imus, who spent more than half a century in radio and television skating along the edge of propriety and occasionally falling into the abyss of the unacceptable, died Dec. 27 at a hospital in College Station, Tex. He was 79. In a roller-coaster career in which he grew chummy with prominent politicians, repeatedly got suspended or fired for offensive cracks, abused drugs and touted health foods, Mr. Imus won a loyal following, made millions and transformed himself from a bad-boy DJ into a host whose program became a nearly mandatory stop for presidential candidates. Read the obituary (Richard Drew/AP)

Finally, he opened the outer hatch and entered space, more than 100 miles above the earth’s surface, connected to his capsule by a 16-foot-long tether. A skilled amateur painter, Mr. Leonov found the vista “indescribably beautiful.”

“I said to myself, ‘It’s true, the Earth is round,’ ” he later said.

His spacewalk was captured by two film cameras that produced remarkably clear images, including some in color.

“It was so quiet I could even hear my heart beat,” Mr. Leonov told London’s Observer newspaper in 2015. “I was surrounded by stars and was floating without much control. I will never forget the moment. I also felt an incredible sense of responsibility. Of course, I did not know that I was about to experience the most difficult moments of my life — getting back into the capsule.”

When he attempted to reenter the air lock leading to the space capsule, Mr. Leonov could not climb through the hatch. His spacesuit had expanded and become almost rigid.

“Near the end of my walk,” he told the New York Times magazine in 1994, “I realized that my feet had pulled out of my shoes and my hands had pulled away from my gloves. My entire suit stretched so much that my hands and feet appeared to shrink.”

He decided that his only option was to open a valve to release air from inside his spacesuit. It deflated enough to allow Mr. Leonov to enter the capsule’s air lock headfirst, but the change in pressure left him at risk of decompression sickness. His spacewalk lasted only 12 minutes, but his body temperature had risen so much that sweat was sloshing in the leggings of his spacesuit.

“I didn’t report this down to Earth,” Mr. Leonov said in 1999. “I knew the situation better than anyone else.”

It would be decades before the dangers he encountered were fully known. Mr. Leonov also revealed, years later, that he had a suicide pill in his helmet, in case he could not return to the spacecraft.

Once he was back inside the capsule, it began to roll uncontrollably. Oxygen levels in the cabin became dangerously high, but eventually the cosmonauts were able to stabilize the craft for its return to Earth.

When the automated reentry system failed, Mr. Leonov and Belyayev flew their craft manually, tumbling wildly until its parachutes opened. They came to rest in a dense forest in the Ural Mountains, about 1,000 miles from their intended landing spot.

Surrounded by several feet of snow, the two cosmonauts stayed in the capsule as temperatures fell below zero. It took more than two days before they were rescued by helicopter.

His feat made Mr. Leonov a national hero, and he was expected to be the first person from his country to walk on the moon. Before the United States could do so, Soviet spaceships circled the moon and landed on its surface.

But other test flights failed, and the booster rocket designed to propel the Soviets’ lunar mission exploded on the launchpad. The space race was won by the United States, culminating in the Apollo 11 mission, which touched down on July 20, 1969, accompanied by astronaut Neil Armstrong’s memorable words as he stepped onto the moon’s Sea of Tranquility: “That’s one small step for man, one giant leap for mankind.”

Alexei Arkhipovich Leonov was born May 30, 1934, in the Siberian village of Listvyanka. He was from a large family, and his father, a onetime coal miner and farmer, spent time in a Soviet gulag for dissent.

Young Alexei was transfixed by aviation from an early age and also studied art. He entered the Soviet air force in 1953 and trained as a fighter pilot and parachutist.

In January 1969, Mr. Leonov was in a motorcade entering the Kremlin when a man wearing a police uniform opened fire with two automatic handguns. Mr. Leonov’s limousine was struck by more than a dozen shots, apparently intended for Soviet leader Leonid I. Brezhnev, who was in a different car. Mr. Leonov’s driver was killed.

“I looked down and saw two bullet holes on each side of my coat where the bullets had passed through,” Mr. Leonov said in 1994. “A fifth bullet passed so close to my face I could feel it go by.”

In 1975, Mr. Leonov returned to space as part of the first joint U.S.-Soviet space effort. His capsule docked with an Apollo spacecraft under the command of NASA astronaut Thomas P. Stafford. They shook hands through a connecting portal and became close friends.

“In the eyes of all of humanity,” Mr. Leonov said, “we showed the best side of man.”

Survivors include his wife, Svetlana, two daughters and several grandchildren.

Mr. Leonov became director of the Soviet cosmonaut corps and retired in 1992. He later worked in banking and exhibited his paintings worldwide, including at the National Air and Space Museum in Washington.

Fluent in English and fond of jokes, he was a popular speaker at gatherings of space aficionados. Author Arthur C. Clarke named a spacecraft after Mr. Leonov in his 1982 novel, “2010,” a sequel to “2001: A Space Odyssey.”

Mr. Leonov came to regret the secrecy and suspicion surrounding the Cold War competition in space.

“If we could have gotten together earlier,” he said in 1990, “we would already have built an international observatory on the moon and we would be flying to Mars right now.”

An earlier version of this story incorrectly stated that Soviet spacecraft obtained lunar soil samples before Apollo 11 reached the moon in 1969. The soil samples were obtained by the Soviet Union in 1970.