The man, in his 50s, got into difficulty at about midnight on Monday when crossing land being developed as housing in Shrewsbury, Shropshire.
He fell into the trench, which was "shoulder-width", and became stuck.
A hazardous area response team managed to pull him free using an aerial ladder platform.
He is thought to have broken his ankles, a West Midlands Ambulance Service spokesman said.
"Given the nature of the location, a building site, there was a very real risk of the trench collapsing, so safety was the number one priority," added the spokesman.
Guy Williams, from Shropshire Fire and Rescue Service, told BBC Radio Shropshire there was an "irony" as firefighters had been practising a similar rescue scenario in a training exercise earlier that evening.
A man who was trying to take a short cut home was unable to move when he became wedged in a trench, emergency services have said.