All 12 members of a youth football team and their coach have been rescued from a cave in northern Thailand, bringing an end to a massive operation that has captured headlines for more than two weeks.

Four remaining boys and their 25-year-old coach Ekapol Chantawong emerged from the Tham Luang cave complex on Tuesday, after eight of their teammates had already been saved on Sunday and Monday.

“Twelve Wild Boars [team members] and their coach are out of the cave,” the Thai Navy SEALs said on Facebook on Tuesday. “Hooyah,” the post added.

The first boy to exit the cave on Tuesday came out on 16:06 local time (09:06 GMT), Thai Navy SEALs said, six hours after rescue operation officials said 19 divers had entered the cave complex.

Nearly three hours later, the last individual was reported to have emerged from the cave.

The rescue of the last five members of the team marks the end of an operation [Vincent Thian/AP]

The group will now be transferred to a hospital in Chiang Rai’s state capital where they will stay for observation for at least seven days.

Earlier on Tuesday, rescue operation chief Narongsak Osottanakorn told reporters the remaining five would all be extracted on the same day.

{articleGUID}

The rescue of the last five members of the Wild Boar football team marks the end of an operation involving more than 1,000 rescue workers.

One former Thai military diver died on Friday after passing out in the cave.

Saman Kunan, a 38-year-old volunteer, was placing oxygen canisters along the route divers had to take to get to the children and could not be revived.

Narrow passageways

The 12 boys, aged 11 to 16, and their coach became trapped inside the cave on June 23, when floodwaters caused by heavy monsoon rains blocked the entrance.

Nine days later, they were found dishevelled and emaciated but alive on a muddy ledge about four kilometres inside the complex cave system.

The boys were found dishevelled and emaciated on a muddy ledge inside the cave [Thai Navy SEALs via Reuters]

It took days for rescue authorities to decide on how the football team should be extracted from the cave, with no attractive options available.

Officials weighed plans including letting the boys dive out, reaching them via a yet-to-be-found shaft in the mountainside or waiting for water levels to drop until they could walk out, which could have taken months.

Depleting oxygen levels inside added pressure to the operation and on Sunday a high-risk rescue operation got under way which involved the boys diving out accompanied by elite divers.

The multi-hour journey towards the cave’s mouth reportedly included passageways as narrow as 40 centimetres. Some of the boys did not know how to swim.

‘Good health’

On Tuesday morning, the permanent secretary of the public health ministry, Jesada Chokedamrongsuk, told reporters the eight boys rescued in the past two days were “in good health”, with no fever and “in a good mental state”.

Two of the four boys who were rescued on Sunday and were given antibiotics after showing signs of pneumonia, the health official said. He added that all four boys from the first rescued group could now eat normal foods, though nothing spicy.

“The kids are footballers so they have high immune systems,” Jedsada told repoters.

“Everyone is in high spirits and are happy to get out. But we will have a psychiatrist to evaluate them.”

Family members were allowed to visit the four boys who were rescued first on Monday evening, but they were kept separated by a glass window because of fears over infections.

The ordeal of the Wild Boar football squad has gripped people in Thailand and all over the world, with cartoons expressing support for the team and rescue workers getting shared widely on social media.

#พาทีมหมูป่ากลับบ้าน

Boar go home. pic.twitter.com/NHX9gi5OAy — In my name it has hope (@4jingjinx) July 8, 2018

Volunteers flocked to the cave site to contribute to the rescue operation, cooking meals and diverting water from flowing into the cave.

Experts have said the team could experience mental health issues after the ordeal and would require support.

“Several of them may be agitated, they may be irritable. They may be also acting out in terms of trying to deal with their emotions,” Andrea Danese, a Psychiatry lecturer at King’s College in London, told Al Jazeera.

A teacher of the Mae Sai Prasitsart school, attended by many of the boys, said preparations were made to manage the mental health impacts on the boys and that they would not have to sit an exam scheduled for next week.