All twelve boys and their soccer coach have been successfully rescued from a Thai cave complex after an 18-day ordeal that gripped the world.

Because the team was trapped in an underground tunnel, 4 kilometres (2.5 miles) from the mouth of the cave, getting them out was an ordeal: The boys had to travel that entire distance, tethered to two cave divers with oxygen tanks.

This graphic shows exactly how the team was taken out of the cave:

thaisoccerteam escape diagram(Samantha Lee/Business Insider)

About 1 kilometre (0.6 miles) of the journey was completely underwater, where everyone had to wear full face masks.

And because the cave's tunnels are dark, the divers also had to hold onto a 4.8 kilometre (3 mile)-long rope and be guided by lights back to the main entrance.

The team was also given anti-anxiety medication to calm them while the divers got them out.

The last four boys and their 25-year-old soccer coach were extracted from the Tham Luang cave network on Tuesday evening, and are being taken to a nearby hospital.

Eight other boys are currently there recovering after being pulled out on Sunday and Monday. They have been kept in a sterilised isolation unit, required to eat soft, plain, and non-spicy food, and are not allowed to watch TV.

This article was originally published by Business Insider.

More from Business Insider: