Four down, eight to go.

Two pairs of boys from the 12-member soccer team trapped with their coach in a flooded Thai cave for 16 days finally emerged from their underground hellhole Sunday in a death-defying rescue.

Local officials called the treacherous operation a race against time as the four “exhausted’’ boys were led out of the murky, winding cave system by expert divers while the water was low — and before another monsoon was set to hit the region Monday and Tuesday.

More than three dozen doctors were at the scene to quickly assess the freed boys as they were loaded onto stretchers.

Three of the kids were then rushed by helicopter to Prachanukrua Hospital in the city of Chiang Rai about 35 miles away, while the fourth was taken by ambulance.

Provincial Gov. Narongsak Osatanakorn declared the four boys’ conditions “perfect,’’ adding, “Everybody’s happy’’ — but local media reported that one of the kids needed critical care.

Narongsak had dubbed Sunday to be “D-day” as the complicated effort was launched in the morning and the effort was no small miracle.

Officials had initially expected it to take 11 hours to shepherd just one boy along the nearly 2-mile dark and dangerous exit route. But a recent spell of dry weather allowed workers to pump more than a foot of water from the flooded cave complex before the rescue began, shaving hours off the operation, authorities said.

Still, the boys — none of whom knew how to swim before they became trapped — had to dive and crawl between spaces so narrow that rescuers were forced to unstrap their air tanks in order to squeeze through fissures in the limestone.

Some of the claustrophobia-inducing passages were no more than 2 feet wide.

The first boy emerged at 5:40 p.m. local time, or 4:40 a.m. New York time Sunday, hugging the frogmen who saved him as he drew his first breaths of fresh air.

The sun was setting as the second child was guided out at 6 p.m. local time, catching his first glimpses of daylight in more than two weeks.

The other pair of boys came out of the cave two hours later, about 10 minutes apart, officials said.

An Australian doctor who had entered the cave and checked the boys’ health Saturday night selected the four because they were the weakest, reports said.

“Four have been [brought] out from the cave site, four have been rescued — we consider that a great success,’’ Osatanakorn said, according to the Guardian.

But “our job is not completely done,’’ he said. “We will have to do the next mission as successfully as the one we did today. The rest of the kids are in the same spot.”

Officials said their second rescue run would not begin for another 10 to 20 hours because they had to replenish the scuba tanks placed along the precarious route.

The tanks — which were set roughly every 30 yards to ensure the divers and kids had enough oxygen as they made the slow trudge out of the cave — were too low to immediately continue, officials explained.

“I can’t tell you exact timing of the next operation — I have to check all factors are stable,’’ Osatanakorn said. “The operation then will be carried out.”

Former Thai Navy SEAL Saman Gunan died Friday while placing tanks, when his own apparatus ran out of air.

Officials said it could take up to four days before the rest of the team is all free — depending on how monsoon rains impact water levels inside the cave system.

Rain began Sunday and was expected to intensify in the next two days.

The nation’s prime minister, Prayuth Chan-ocha, was planning to visit the rescue operation Monday, according to a government spokesman.

Sunday’s rescue began around 10 a.m. as a group of 10 elite international divers and five Thai Navy SEALs entered the cave complex and made their way to the cavern deep inside the network where the boys and their coach had been sheltering.

Three more divers followed around 2 p.m., setting up “support diving efforts” along the rescue route and helping to secure the guide-rope system in a particularly dangerous stretch of the track, the Guardian said.

Each of the four boys was then escorted out by two divers — one in front and one behind them.

The boys were tethered to the lead diver, who also carried an air tank attached to the kids’ full-face diving masks, according to reports.

The guideline kept rescuers on the right path as they navigated the labyrinth’s dark waters.

The kids could walk much of the way through the cave system because workers had been able to pump out enough water out, authorities said.

As the boys finally emerged from their dank dungeon, cheers erupted at the scene.

“After 16 days of waiting, we get to see the faces of the Wild Boars,” Osottanakorn said, referring to the soccer team’s name.

The hospital where the boys were taken to had its eighth floor ready for the incoming kids, as well as their families, authorities said.

Loudspeaker announcements outside the hospital Sunday warned street vendors to “keep off the road” and to “not obstruct the transfer mission.”

Doctors will evaluate whether the kids suffered any long-term health effects from the ordeal, officials said.

For example, the physicians will likely check whether low oxygen levels inside the cavern where the boys sheltered could have harmed them, experts said.

“As soon as they get out, that’s what they’ll be checking: their oxygen levels and their breathing,” Dr. Darria Long Gillespie of the University of Tennessee told CNN.

The boys — between ages 11 and 16 — went into the cave after a team practice June 23 and became trapped after waters rose inside the cave. They initially entered the cave to write their names on a back wall as a local rite of passage.

A total 90 divers — 50 of whom are not Thai — have been involved in rescue operations.

With Post wires