MUNICH — Johann Westhauser, the spelunker trapped in Germany’s deepest cave after becoming injured by falling rock on June 8, reached the surface Thursday in a rescue effort that relied on help from six countries.

Westhauser, 52, a speleologist from Stuttgart, was hoisted on a stretcher from a depth of almost 3,280 feet in the Riesending cave system near the Bavarian town of Berchtesgaden. The task to bring him to safety, which began after he sustained skull and brain injuries in the accident, was completed late in the morning, according to a press release from local authorities. A crew of more than 100 doctors, engineers and emergency personnel collaborated to transport him through the maze that stretches for more than 12 miles inside the Untersberg massif, which straddles the German-Austrian border. Rescue teams from Germany, Switzerland, Austria, Italy, Croatia and Slovenia negotiated waterfalls, passages as narrow as a human body, and a vertical shaft in temperatures close to freezing. Westhauser was part of the group that discovered the underground canyon in 1995.

“This has been the most complex and extensive cave rescue operation ever,” Andreas Baecker, a member of the Bavarian mountain rescue service, said in an earlier telephone interview.