Emergency services could only see the man’s head when they arrived at the site in Smethwick and had to dig out the earth around him.
A West Midlands Ambulance Service spokeswoman said: “Crews were called to reports of a man who had become trapped in a trench that he had been working in.
“It is believed that one of the sides collapsed in on the hole, which was approximately 18 feet deep.
“On arrival at the scene crews could only see the man’s head. Ambulance personnel quickly dug away some of the earth to help free the man.
“Emergency services worked closely together for over two and a half hours to extricate the man safely from the trench. Crews used specialist stretcher equipment and a hoist to finally release him from the hole.
“The man, believed to be in his early 20s, was treated for chest and potential pelvic injuries and was conveyed to the Major Trauma Centre at Queen Elizabeth Hospital Birmingham for further assessment and treatment.
The spokeswoman said: “A trauma doctor travelled on board the ambulance along with the crew continuing to provide emergency medical treatment whilst en route to hospital.
“The hospital was pre-alerted and medics were on standby awaiting the arrival of the man.”