The rescued boy has been transferred from cave entrance to the field hospital. (File)

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 said on Tuesday, a successful end to a perilous mission that has gripped the world.

"The 12 Wild Boars and coach have emerged from the cave and they are safe," the SEAL unit said on its official Facebook page.

The "Wild Boars" soccer 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 13, hungry and huddled in darkness on a muddy bank 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 last five were brought out of the cave on stretchers, one by one over the course of Tuesday, and taken by helicopter to hospital.

Three members of the 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.

Officials have not been commenting on the rescue mission as it has been taking place, so it was not clear what condition those brought out on Tuesday were in.

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.

Authorities have not confirmed the identity of the rescued boys and some of their parents said they had not been told who had been brought out. They were not allowed to visit the hospital where the boys were taken.

The rescued boys had not been identified out of respect for the families whose sons were still trapped, officials had said.

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.

© Thomson Reuters 2018