You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
The "Wild Boars" football team, aged between 11 and 16, and their 25-year-old coach became trapped on June 23 while exploring the cave complex in the northern province of Chiang Rai when a rainy season downpour flooded the tunnels.
Rescuers carried out the last boy at just after 11pm (NZ time) on Tuesday and his coach followed some 20 minutes later, CBS reported.
"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 Navy SEAL unit, which led the rescue, said on its Facebook page, adding all were safe.
British divers found the 13, hungry and huddled in darkness on a muddy bank in a partly flooded chamber several kilometres inside the Tham Luang cave complex.
After pondering for days how to get the 13 out, a rescue operation was launched on Sunday when four of the boys were brought out, tethered to rescue divers.
Another four were rescued on Monday and the last four boys and the coach were brought out on Tuesday, prompting rounds of spontaneous applause as ambulances and helicopters passed.
Celebrations were tinged with sadness over the loss of a former Thai navy diver (38) who died on Friday while on a re-supply mission inside the cave.
"I want to tell the coach thank you so much for helping the boys survive this long," said one Chiang Rai woman wearing a traditional dress, tears brimming in her eyes.
"I remember all of their faces, especially the youngest one. He's the smallest one and he doesn't have as much experience as the others... I felt like he was one of my own children and I wanted him to come home."
Rescuers brought out the last five on stretchers, one by one over the course of Tuesday, and they were taken by helicopter to hospital.
Chief of the rescue mission Narongsak Osottanakorn addressed reporters at the end of the 17-day mission, arriving at a media centre to a round of applause.
He confirmed that a medic and all navy SEAL divers involved in the rescue mission had also left the cave safely.
"Nobody thought we could do it. It was a world first," he said. "It was Mission Possible for Team Thailand.
"The heroes this time are people all over the world," he added, referring to the multinational team that assisted in the operation.
"This mission was successful because we had power. The power of love. Everybody sent it to the 13."
The eight boys brought out on Sunday and Monday were in good health overall and some asked for chocolate bread for breakfast, officials said earlier.
Two of the boys had suspected lung infections but the four boys from the first group rescued were all walking around in hospital.
Volunteers from as far away as Australia and the United States helped with the effort to rescue the boys. U.S. military personnel also helped.
Authorities did not reveal the identity of the boys as they were brought out. Parents of the four boys rescued on Sunday were allowed to see them through a glass window at the hospital, public health officials said on Tuesday, but they will be quarantined for the time being.
The boys were still being quarantined from their parents because of the risk of infection and would likely be kept in hospital for a week for tests, officials said earlier.
'HOOYAH! MISSION ACCOMPLISHED'
The rescue dominated front page headlines in Thailand.
"All Wild Boars Saved," read one headline.
"Hooyah! Mission accomplished," read another, echoing the rallying cry of the Thai navy SEALs involved in the rescue.
The hashtag #Hooyah was also hugely popular with Thai netizens wanting to show their support for the hundreds of rescuers, including divers from around the world, who helped to get the boys out.
A Google search on Tuesday for the words "Thai cave rescue" revealed 359 million results, with interest peaking since last week when British divers found the boys and the rescue mission began.