Navy SEALs who rescued Thai soccer team from cave almost didn't make it out, military officials say The main pump went out soon after the soccer coach was extracted from the cave.

Thai Navy SEALs who were clearing the flooded cave where 12 boys and their soccer coach were rescued, barely made it out after the main pump that had been siphoning water out of the cave failed, Thai military sources who were directly involved in the operation told ABC News.

The system, which had pumped hundreds of millions of gallons of rainwater out of the cave over the past 18 days, gave out soon after rescuers extracted the coach and the four Thai Navy Seals who had volunteered to stay with them. Thai SEALs and support teams, who were carrying air tanks from the third to the second chamber of the labyrinthine cave, soon noticed the waters rising. The third chamber filled, then the second and then the first, as crews scrambled to avoid the kind of cave flooding that had trapped the soccer team on June 27, according to Thai military sources.

Dozens of military personnel and civilians began abandoning the cave, leaving behind hundreds of air tanks. Some of the tanks belonged to the SEALs. Others had been donated by the king of Thailand, Thai military sources said.

On Tuesday, the remaining four boys and the coach were successfully rescued from the cave at the base of a mountain known locally as the Sleeping Princess. That day’s rescue took about nine hours, according to Thai Navy SEALs. They emerged from the cave to cheers by the military and support staff, Thai military sources said.

The Tham Luang Nang Non cave, located within the Khun Nam Nang Non Forest Park, is known in Thailand as the country's longest cave. It’s twisting six mile long passageways reach all the way into the neighboring country of Myanmar.

The Thai military sources said the pumps lasted just long enough to successfully rescue the final four boys and their soccer coach. The five hauled out nearly at once in a long convoy of divers, support teams, and medics, according to the sources. Each of the nine chambers had a doctor waiting, and the boys were evaluated at each chamber.

The boys were given anti-anxiety medication before they were rescued, Thai Prime Minister Prayut Chan-o-cha revealed, according to The Associated Press.

"Like us, we take antihistamines to make us feel well, not excited, not writhe, not taking the mask out," the prime minister said. "It's called Anxiolytic -- something to make them not excited, not stressed."

None of the 13 survivors had diving experience and most couldn't swim, according to Thai military sources.

The rescued were finally carried out on stretchers from the second chamber, wearing surgical masks to ward off germs, and sunglasses because of their new sensitivity to light, the Thai military sources said.

The youngest of the group, who was very weak, was the first one to be whisked away in an ambulance Tuesday. His condition was apparently of such concern that medics didn't even wait for police cruisers to escort them to a nearby helipad, the Thai military sources said.

The coach was the last one out and seemed to have been suffering from hypothermia as he emerged from the cave shivering and wrapped in a thermal blanket, said the Thai military sources.

After their discovery deep in the belly of that cave, divers began to deliver sticky rice and pork in waterproof bags to the four SEALs and the soccer team, according to the sources. The food had been cooked in the camp right outside the mouth of the cave, but the boys could only nibble on the rice because they’d grown so weak, the Thai military sources said.

The "Wild Boar" youth soccer team and its 25-year-old coach were exploring the cave on June 23 when heavy rains flooded their exit route.

The search-and-rescue operation began on Sunday just ahead of monsoon rainstorms that pelted the region early Wednesday and threaten to flood the cave again.

A team of 19 divers entered the cave to replenish oxygen supplies, and two divers escorted each of the boys out of the underwater labyrinth, Thai military sources said.

One volunteer died from what the Thai Navy Seals called a “medical condition” as he was restocking supplies along the route.