The last four boys and a football coach trapped inside a northern Thailand cave for more than 17 days have successfully been retrieved, sparking celebrations across Thailand and praise for the daring rescue operation from around the world.

Narongsak Osatanakorn, the head of the joint command centre coordinating the rescue operation said on Tuesday evening:  "Today team Thailand, achieved mission impossible."

Before 4pm on Tuesday, the first of the remaining four boys in the cave emerged and was rushed to hospital in the nearest city of Chiang Rai. Confirmation of two more followed soon after.

About two hours later the Thai navy Seals, who have led the operation, announced the entire Wild Boars football team and their coach had been freed: “The 12 Wild Boars and coach have emerged from the cave and they are safe,” they posted on their official Facebook page. 

Like the eight boys rescued on Sunday and Monday, the boys and the coach freed on Tuesday will undergo detailed testing of their eyes, nutrition levels and mental health, with blood samples to be sent to Bangkok to test for any infectious diseases.

Health officials said that some of the first boys freed had elevated white-blood cell levels, indicating infections, and two showed signs of pneumonia but were responding well to treatment.