CHIANG RAI, Thailand (Reuters) - Rescuers freed the last four of 12 Thai boys and their soccer coach from deep inside a flooded cave on Tuesday, a successful end to a perilous mission that gripped the world for more than two weeks.

The “Wild Boars” soccer 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.

“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, 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, prompting rounds of spontaneous applause as ambulances and helicopters passed.

Celebrations were tinged with sadness over the loss of a former Thai navy diver 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.

Slideshow ( 27 images )

“POWER OF LOVE”

“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.”

Slideshow ( 27 images )

Officials said details of the rescue operation would be revealed on Wednesday.

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.

U.S. 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!”

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.