Their plight and the massive, dangerous three-day-long operation to free them gripped the world’s attention.
The group was cut off on 23 June after heavy rains flooded their way back out.
They were found by British divers last week, huddled in darkness on a ledge amid fears they could be forced to stay there for months until water receded.
There were cheers as a daring rescue operation involving dozens of divers and hundreds of other rescue workers came to an end on Tuesday evening.
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.
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.
A team of 90 expert divers – 40 from Thailand and 50 from overseas – worked in the Tham Luang caves.
They guided the boys and their coach through darkness and submerged passageways towards the mouth of the cave system.
Getting to and from the trapped group was an exhausting round trip, even for experienced divers.
The process included a mixture of walking, wading, climbing and diving along guide ropes.
Wearing full-face masks, which are easier for novice divers than traditional respirators, each boy was accompanied by two divers, who also carried his air supply.
The toughest part was about halfway out at a section named “T-Junction”, which was so tight that the divers had to take off their air tanks to get through.
Beyond that a cavern – called Chamber 3 – was turned into a forward base for the divers.
There the boys could rest before making the last, easier walk out to the entrance. They were then taken to hospital in Chiang Rai.
The last of the rescue team – three Thai Navy Seals and a doctor – emerged from the cave complex some hours after the last member of the trapped group was released.
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.
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. (Courtesy BBC)