Park rangers came across the elephant calves on Wednesday afternoon as they were struggling to climb the pit’s slippery banks, officials of Thap Lan National Park said.
Some of the rangers went to get help, while others spent the night with the baby elephants.
On Thursday, as the elephants wallowed together at one side of the pit, rangers at the other side spent four hours using hoes and pickaxes to dig out enough mud to form a ramp.
Footage of the rescue released by the Department of National Parks shows the animals climbing out of the muck one by one and quickly heading into the forest, a few dozen metres away.
The rangers cheer the elephants on, with comments like “Go, go on, child!”
One elephant can be seen to struggle, slip and fall, but finally all make it out of the muck.
The last of the animals then lingers, after all the others have made it past the tree line.
It faces the rangers for a moment, turns, pauses and finally runs into the jungle.
“Gone, they’re gone,” cries a ranger, as the rescue crew comes together to celebrate.
Park chief Prawatsart Chantep said there were signs a herd of elephants believed to be related to the trapped infants was circling the area.
Elephants are the official national animal of Thailand, and for a time graced the country’s flag when it was still called Siam.
But development has sharply reduced their natural habitat and shrunk their numbers. They are notorious for raiding farmers’ fields for food, especially sugar cane.
Several people are killed each year by angry elephants.
Last November, a driver on a road near another park in the northeast struck the hind legs of one when it wandered out of the jungle at dusk. The animal responded by stomping on the car, destroying the engine and killing the driver.
Additional reporting by Associated Press