The graveyard worker was buried up to his knees after the walls of the grave he was digging at Kintore Cemetery in Aberdeenshire fell in.
The emergency services were alerted at 1.55pm and a fire engine from Inverurie was sent to the scene.
Firefighters used buckets to help free the trapped worker and he stepped out of the grave shortly after 3pm.
He was then placed in the care of paramedics.
Inverurie watch manager Graeme Duncan said: “The ground appeared to be very sandy and that’s likely to have caused the sides to cave in. Others working at the graveyard tried to help him initially, before they called the fire service for assistance.”