The dramatic rescue marks the end of a more than two-week ordeal which began when the “Wild Boars” team and their coach became trapped inside the flooded Tham Luang cave on the border with Myanmar on June 23.

"We've rescued everyone. We've succeeded," rescue mission chief Narongsak Osotthanakorn told reporters.

Four Thai Navy Seals and a Thai doctor were the last people to emerge from the cave.

A picture showing the four Navy Seals with a thumbs up gesture was posted on Facebook.

Narongsak said more than 1000 members of the army helped with the rescue effort and he is delighted with the outcome.

"We did what no-one expected we could do," he said, adding that Thailand demonstrated a level of co-operation that is now a model for the rest of the world.

"Mission accomplished," he said.

AAP

The Thai Navy Seals, who led the rescue effort, earlier confirmed the evacuation of the whole football team.

"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 Thai navy SEAL unit said on its official Facebook page.

There is a sense of relief here in Chiang Rai, but we are mostly just willing confirmation that all boys are out of the Tham Luang cave. For once, hopefully, a story with a happy ending. @SBSNews — Omar Dabbagh (@Omar_Dabbagh) July 10, 2018

The Thai SEALs and elite foreign divers extracted the final batch of four boys, plus the 25-year-old coach, on Tuesday afternoon via a perilous escape route that required them to squeeze through narrow, water-filled tunnels.

"All 12 'Wild Boars' and coach have been extracted from the cave," the SEALs said in a Facebook post.

"All are safe," they added, signing off with what has become their trademark "Hooyah" to celebrate the successful extractions of the other boys over the previous two days.

The Thai doctor and three Navy Seals who volunteered to stay with the team for eight days have also left the cave.

The condition of the evacuees is unknown, but they have been transported to the hospital in Chiang Rai for medical treatment.

0:00 00:00 / 00:00 Share Share on Twitter

Share on Facebook

Cheers for rescued boys and coach

Locals in Chiang Rai said they were elated over the successful outcome.

One woman told SBS there is an almost palpable collective sigh of relief.

“I feel relieved, everyone feels relieved as well," she said. "Very happy.”

Another said she had never met the 13 members of the football team who were trapped in the cave, but feels like she knows them.

"[It is] the best feeling. I don’t know how to say it," she said. "It’s just really good."

AAP

“They are 13 strangers we have never met, but we really want to see them.”

Another resident said she shared the sentiment, claiming the kids as her own.

"I have no boy, but now I have 13 boys. They are my boys. I feel very, very happy and I think the people all around the world they feel the same," she said.

“I think they are not Thai boys, but they are the boys of the world. They are our kids."

Volunteer rescue workers marked the occasion with song and dance.

Britain’s Manchester United football club said on its official Twitter page that it was relieved to learn that the 13 were safe and extended an invitation for the group and their rescuers to visit its Old Trafford stadium.

0:00 Chief of Thai cave rescue operation comments after boys rescued 00:00 / 00:00 Share Share on Twitter

Share on Facebook

International praise for rescue team

On Monday, Prime Minister Prayuth Chan-ocha said he would host a celebration for all of those involved in the multinational rescue effort.

“We will host a meal for all sides,” said Prayuth.

United States president Donald Trump also joined the celebrations, praising the Thai Navy Seals for a "great job".

On behalf of the United States, congratulations to the Thai Navy SEALs and all on the successful rescue of the 12 boys and their coach from the treacherous cave in Thailand. Such a beautiful moment - all freed, great job! — Donald J. Trump (@realDonaldTrump) July 10, 2018

Bhutan’s prime minister, Tshering Tobgay, adopted the 'hooyah' phrase used by the Thai Navy Seals to express his congratulations.

Bhutan celebrates the rescue of the thirteen Wild Boars. Congratulations Thailand!

Hooyah!!!#ThailandCaveRescue — Tshering Tobgay (@tsheringtobgay) July 10, 2018

British prime minister Theresa May saluted the "bravery of all those involved".

Delighted to see the successful rescue of those trapped in the caves in Thailand. The world was watching and will be saluting the bravery of all those involved. — Theresa May (@theresa_may) July 10, 2018

The spokesperson for German chancellor Angela Merkel also welcomed the news.

Was für eine wunderbare Nachricht aus #Thailand! So vieles zu bewundern: der Durchhaltewille der tapferen Jungs und ihres Trainers, das Können und die Entschlossenheit der Retter. — Steffen Seibert (@RegSprecher) July 10, 2018

Tribute paid to navy diver

The celebrations were tinged with sadness, however, as the contribution of Saman Kunan was remembered.

The voluntary diver with the Thai Navy Seals died last week while trying to save the trapped boys.

Italian football team AS Roma and the Spanish royal family posted messages honouring his contribution.

The best football news of the summer – ALL 12 young Thai players and their coach have been rescued after being trapped in a cave in Thailand for two weeks.



Our thoughts are with the family of ex-Navy SEAL diver Saman Kunan who died after delivering the boys oxygen. A real hero pic.twitter.com/UKW5tXfGei — AS Roma English (@ASRomaEN) July 10, 2018

Nuestra admiración y reconocimiento al buzo español Fernando Raigal, que ha trabajado sin descanso en un rescate memorable. También nuestro recuerdo para Sanan Gunan, voluntario fallecido en los trabajos. #ThaiCaveRescue #ThaiRescueMission @MFAThai — Casa de S.M. el Rey (@CasaReal) July 10, 2018

Ups and downs of rescue mission

The 12 boys, aged from 11 to 16, and their coach, ventured into the Tham Luang cave in mountainous northern Thailand on June 23 after football practice and got caught deep inside when heavy rains caused flooding that trapped them on a muddy ledge.

They spent nine harrowing days trapped in darkness until two British divers found them, looking gaunt but otherwise offering smiles to the divers and appearing to be in remarkably good spirits.

0:00 How the boys trapped in a Thai cave have been freed 00:00 / 00:00 Share Share on Twitter

Share on Facebook

But the initial euphoria at finding them dissipated as authorities struggled to devise a safe plan to get them out, with the shelf more than four kilometres (2.5 miles) deep inside the cave and the labyrinth of tunnels leading to them filled with water.

Authorities mulled ideas such as drilling holes into the mountain or waiting months until monsoon rains ended and they could walk out, with the rescue chief at one point dubbing the efforts to save them "Mission Impossible".

With oxygen levels in their chamber falling to dangerous levels and monsoon rains threatening to flood the cave up above the ledge where the boys were sheltering, rescuers decided on the least-worst option of having divers escort them out through the tunnels.

AAP

The escape route was a challenge for even experienced divers. The boys had no previous diving experience so the rescuers trained them how to use a mask and breathe underwater via an oxygen tank.

One fear had been that they would panic while trying to swim underwater, even with a diver escorting them.

The death of a former Thai Navy SEAL diver who ran out of oxygen in a flooded area of the cave on Friday underscored the dangers of the escape route.

The ups and downs of the rescue bid entranced Thailand and also fixated a global audience, drawing support from celebrities as varied as US President Donald Trump, football star Lionel Messi and tech guru Elon Musk.

Health concerns

Now they are out, concerns are set to focus on the physical and mental toll of the ordeal.

Experts warned that drinking contaminated water or otherwise being exposed to bird or bat droppings in the cave could lead to dangerous infections.

They also said counselling would be needed to deal with the psychological trauma of spending so long not knowing whether they were going to survive.

But there were some promising initial signs.

Read More Rescued Thai boys could face toughest challenge yet

Medical chiefs reported on Tuesday morning that the eight boys rescued on Sunday and Monday were in relatively good mental and physical conditions.

"All eight are in good health, no fever... everyone is in a good mental state," Jedsada Chokdamrongsuk, permanent secretary of the public health ministry, said before all 13 had been rescued.

Nevertheless, the boys would remain in quarantine in hospital until doctors were sure they had not contracted any infections from inside the cave.

Even before the final rescues, tributes began for the courage of the boys and their ability to survive the ordeal.

"I cannot understand how cool these small kids are, you know? Thinking about how they've been kept in a small cave for two weeks, they haven't seen their mums," Ivan Karadzic, who runs a diving business in Thailand and has been involved in the rescue mission, told the BBC.

"Incredibly strong kids. Unbelievable almost."

Plight of the boys attracts global attention

Football’s governing body, FIFA, had invited the boys to the World Cup final in Moscow on Sunday. But doctors treating the boys said they would remain in isolation for at least seven days.

The plight of the boys and their coach has drawn international attention since they became trapped when they went into the cave after football practice on June 23.

Divers, engineers, medics and others have flown in from around the world to assist.

Technology billionaire Elon Musk went into the cave on Monday and left the rescue team with a “kid-sized” submarine his company SpaceX had built.

Musk said on Twitter: “Just returned from Cave 3. Mini-sub is ready if needed. It is made of rocket parts & named Wild Boar after kids’ football team. Leaving here in case it may be useful in the future.”

Prime Minister Prayuth Chan-ocha visited the cave during the rescue operation and was quoted by Narongsak as saying he didn’t want to see this kind of incident happen again on Thai soil.