In an indication of how dangerous the journey out was, a former Thai navy diver died in the caves on Friday. Saman Gunan was returning from a mission to provide the group with air tanks when he ran out of oxygen.

Media playback is unsupported on your device

Media captionRescue diver in Thai cave: "I was very scared"

Aged between about 11 and 17, the members of the Wild Boars football team had entered the Tham Luang cave system in the province of Chiang Rai during an excursion with their coach.

Confirming the completion of the rescue operation, the Thai Navy Seals Facebook page announced: "All 12 Wild Boars and coach have been extracted from the cave. All are safe."

And at the house just below the mountains where the men who run the Wild Boars meet, there was laughter, shouts and cheers - and people shook hands in a very un-Thai way, says the BBC Jonathan Head.

'Mission Accomplished'

By Nick Beake, at Chiang Rai hospital

This is the moment Mission Impossible became Mission Accomplished.

Families in Chiang Rai gathered at the hospital to watch the final ambulances bring in their precious cargo. Some said they couldn't believe it, others said they had never lost hope. All wore the brightest of smiles.

Up on the eighth floor, doctors - who declared this morning that the first eight boys to be rescued are doing well - will now be examining their remaining team mates and their coach. Psychologists will be assessing the impact a fortnight trapped underground has had.

The Wild Boars footballers went into the Tham Luang cave as a team. They survived as a team. And tonight, at the end of a remarkable 72-hour rescue, they are together as a team once again.

What next for the boys?

The first eight boys to be rescued - on Sunday and Monday - are still in hospital but said to be in good mental and physical health.

They have undergone X-rays and blood tests, and will remain under observation in hospital for at least seven days.

Media playback is unsupported on your device

Media captionChild psychiatrist: "It will be a challenge for these children to go back to normal life"

Their parents have been allowed to see them through a glass window at the hospital, but they are being quarantined.

Drinking contaminated water in the cave or being exposed to bird or bat droppings in the cave could lead to dangerous infections, experts say.

The boys lost weight during their time in the caves and are keen to eat. They are said to have requested a favourite pork dish, bread and chocolate, but solid food will have to be reintroduced slowly to prevent digestive upset.

They will also need to wear sunglasses for a few days until their eyes readjust to the brighter light.