A daring rescue mission in the treacherous confines of a flooded cave in northern Thailand has saved all 12 boys and their soccer coach who were trapped deep within the labyrinth, ending a grueling 18-day ordeal that claimed the life of an experienced volunteer diver and riveted people around the world.

The Thai navy SEALs, who were central to the rescue effort, posted on their Facebook page Tuesday that the rescue operation was successful.

"We are not sure if this is a miracle, a science, or what. All the thirteen Wild Boars are now out of the cave," the SEALs wrote, referring to the name of the boys' soccer team.

A medic and three Thai navy SEALs who had stayed with the boys on a small, dry shelf deep in the flooded cave have left the cave as well, Chiang Rai Gov. Narongsak Osatanakorn said. He said they are all in strong condition.

"We did something nobody thought possible," Narongsak said.

Cheers erupted at a local government office where dozens of volunteers and journalists were awaiting news of whether the intricate and high-risk rescue mission had succeeded. Helicopters taking the boys to a hospital roared overhead.

People on the street cheered and clapped when ambulances ferrying the boys arrived at the hospital in Chiang Rai city.

Amporn Sriwichai, an aunt of the rescued coach, Ekkapol Chantawong, said she was happy and excited.

"If I see him, I just want to hug him and tell him that I missed him very much," she said.

FIFA had invited the boys to attend the World Cup final, but the boys will not be able to travel in time for Sunday's game because of health concerns. The sport's global governing body, which will meet with Thai soccer officials in Moscow, said they would look to bring the boys to a future event.

After France's World Cup semifinal win over Belgium later on Tuesday, French star Paul Pogba dedicated the victory to the rescued children.

This victory goes to the heroes of the day, well done boys, you are so strong 🙏🏾 #thaicaverescue #chiangrai pic.twitter.com/05wysCSuVy — Paul Pogba (@paulpogba) July 10, 2018

Manchester United also expressed relief over the rescue and invited the boys and their coach, as well as those who saved them, to come see them play this season.

Narongsak had said earlier Tuesday that the day's effort might take longer than the previous two rescue missions, but the final four players and coach were out of the cave within 10 hours of the operation's start. The first day took 11 hours.

Each of the boys, ages 11 to 16 and with no diving experience, was guided out by a pair of divers during three days of operations. The route, in some places just a crawl space, had oxygen canisters positioned at regular intervals to refresh each team's air supply.

Heavy rains in the morning cleared during the day, a reassuring sign for rescuers who feared monsoon rains could imperil the rescue.

Thai Prime Minister Prayuth Chan-ocha, speaking before the final rescue was completed, said the boys were given an anti-anxiety medication to help with their perilous removal from the cave.

Asked at a weekly news conference Tuesday in Bangkok if the boys had been sedated, Prayuth said: "Who would chloroform them? If they're chloroformed, how could they come out? It's called anxiolytic, something to make them not excited, not stressed."

Prayuth said the Tham Luan Nang Non cave would be closed for some time to make it safe for visitors.

"We are not sure if this is a miracle, a science, or what. All the thirteen Wild Boars are now out of the cave." Thai navy SEALs, writing on Facebook about the rescue of 12 youth soccer players and their coach

The eight boys brought out by divers over the previous two days are in "high spirits" and have strong immune systems because they are soccer players, a senior health official said.

Doctors were being cautious because of the infection risk and were isolating the boys in the hospital. They did get a treat, however: bread with chocolate spread that they had requested.

The boys and their coach were trapped in the Tham Luan Nang Non cave that became flooded by monsoon rains while they were exploring it after a soccer practice June 23. Their plight riveted Thailand and much of the world -- from the heart-sinking news they were missing to the first flickering video of the huddle of anxious yet smiling boys when they were found 10 days later by a pair of British divers.

There was one fatality during the dangerous rescue mission. A former Thai navy SEAL died Friday while replenishing oxygen canisters laid at regular intervals along the route out of the sprawling cave.

At a news conference, Jedsada Chokdumrongsuk, permanent secretary at the Public Health Ministry, said the first four boys rescued are now able to eat normal food, though they can't yet take the spicy dishes favored by many Thais.

Two boys possibly have a lung infection, but the first eight who were rescued are generally "healthy and smiling," he said.

"The kids are footballers, so they have high immune systems," Jedsada said. "Everyone is in high spirits and are happy to get out. But we will have a psychiatrist to evaluate them."

It could be at least seven days before they can be released from hospital, Jedsada said.

Family members have seen at least some of the boys from behind a glass isolation barrier, and Jedsada said doctors might let the boys walk around their beds on Tuesday.

It was clear that doctors were taking a cautious approach. Jedsada said they were uncertain what type of infections the boys could face, "because we have never experienced this kind of issue from a deep cave."

If medical tests show no dangers, after another two days parents will be able to enter the isolation area dressed in sterilized clothing and staying 2 yards away from the boys, said Tosthep Bunthong, Chiang Rai Public Health chief.

The Associated Press contributed to this report.