All 12 boys and their soccer coach trapped for more than two weeks deep inside a flooded Thai cave have been rescued, a Thai navy SEAL unit says, marking a successful end to a perilous mission that gripped the world.

"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 SEAL unit said on its Facebook page, adding all were safe.

The team and their coach got trapped on June 23 while exploring the cave complex in the northern province of Chiang Rai after soccer practice and a rainy season downpour flooded the tunnels.

British divers found the team, hungry and huddled in darkness in a partly flooded chamber several kilometres inside the complex, on Monday last week.

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.

Celebrations will be tinged with sadness over the loss of a former Thai navy diver who died last Friday while on a re-supply mission inside the cave in support of the rescue.

"The mission has been accomplished," said Suthee Sommart, 45, a rescuer who had been working in a team scouring for cave openings. "I never lost hope. We always knew they would be alive.

"This mission is very special. We have made history."

Three members of the Thai SEAL unit and an army doctor, who has stayed with the boys since they were found, were the last people due to come out of the cave, the unit said.

It is not yet clear what condition those brought out on Tuesday are in.

The eight boys brought out on Sunday and Monday were in good health overall, although two had suspected lung infections.

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 to undergo tests, officials said earlier on Tuesday.

US President Donald Trump hailed the rescue.

"On behalf of the United States, congratulations to the Thai Navy SEALs and all on the successful rescue of the 12 boys and their coach from the treacherous cave in Thailand," Trump said on Twitter.

"Such a beautiful moment - all freed, great job!"