All twelve members of a boy’s football team and their coach have been rescued, after being trapped in a cave in Northern Thailand for 18 days.

The plight of the group and the massive, dangerous operation to free them has gripped the world's attention.

The first of the boys were brought out on Sunday but the last of the group were only freed on Tuesday evening.

They got stuck deep inside the caves on 23 June after heavy rains caused flooding and cut off their route out.

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.

The Thai navy Seals and Divers , who have been running the operation, confirmed that all 13 were out. “We are not sure if this is a miracle, a science or what”, the Seals said on their Facebook page.

Three navy seals and a doctor, who have been with the boys, are expected to emerge from the cave soon.

After they were found by British divers last week, huddled in darkness on a ledge and cut off from the outside world for nine days, the race began to get them out before the weather deteriorated even further.

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.

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.

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."