Gardaí believe that if the alarm had been raised 20 minutes later, the 15-year-old boy could have drowned.
They also said he could thank the good sense of a concerned member of the public who contacted gardaí after hearing shouting coming from the estuary near Midleton, Co Cork.
Midleton-based Sgt Tom O’Halloran and Garda Conor MacCarthy rushed to the scene at Ballinacurra shortly after midnight.
For a number of minutes they could not contact the youngster, but eventually heard him shouting in the distance. He was so far away that they could not pick him up in the lights of their torches.
“Eventually they made contact with him verbally. He was stuck in the mud and unable to move and the tide was coming in rapidly,” said a Garda spokesman.
At that stage, more gardaí arrived and the fire brigade and a coastal rescue unit were called in to help.
However, realising the urgency of the situation, Sgt O’Halloran contacted local fisherman Tom O’Brien, who brought along a boat.
The duo, along with Garda Martin Hennigan, managed to locate the youngster.
Garda Hennigan and Garda Diane Ryan then managed to extricate the youth from the mud and got him to shore.
The whole operation took an hour to complete and the teenager was taken by ambulance to be treated by SouthDoc.
He was later reunited with his family.
“We estimate that in another 20 minutes he would have been submerged. This young man was extremely lucky. We have to compliment the member of the public who contacted us in the first place,” the Garda spokesman said.
He confirmed the youth was a Junior Cert pupil who lives in the East Cork area.
“The mud flats are known to be inherently dangerous,” said the spokesman.
Gardaí were questioning the boy yesterday about how he came to get bogged down in the mud flats.