All 12 boys of a youth football team and their coach have been pulled from a flooded cave in Thailand, the country's Navy Seals said.
They had been stranded there since June 23 when heavy rain and rising waters left them trapped.
Eight boys were brought out alive over the last couple of days. A fresh operation to save the remaining five people was launched on Tuesday.
With everyone now out it means a successful end to a perilous rescue mission that has gripped the world.
British divers found the 13, huddled on a muddy bank in a partly flooded chamber several kilometres inside the complex, on Monday last week.
The eight boys brought out on Sunday and Monday were in good health overall and some asked for chocolate bread for breakfast, officials said.
Two of the boys had suspected lung infections but the four boys from the first group rescued were all walking around their hospital beds.
They are still being quarantined from their parents because of the risk of infection and would likely be kept in hospital for a week to undergo tests, officials said.
People across Thailand, and the world, have cheered the rescue operation, including at the Mae Sai Prasitsart school where six of the trapped boys are students.
Technology billionaire Elon Musk went into the cave on Monday and left the rescue team with a "kid-sized" submarine his company SpaceX had built, Thailand's interior Minister Anupong Paochinda said.
Musk said on Twitter: "Just returned from Cave 3. Mini-sub is ready if needed. It is made of rocket parts & named Wild Boar after kids' soccer team. Leaving here in case it may be useful in the future."