Two workers stuck up to their shoulders in wet mud inside a Potomac trench were rescued just after 8 p.m. Thursday.

According to Pete Piringer with Montgomery County Fire and Rescue, the accident happened in the 10900 block of Martingale Court around 5 p.m. Thursday while a crew of four men were working on the foundation of a home.

Suddenly, the ground collapsed under their feet, trapping two of them in several feet of wet mud. A third co-worker went to a home next door and asked for help.

A technical rescue team and an urban search and rescue team worked for about three hours stabilizing the hole and pumping air down to talk to the men.

"We were preparing for an extended operation, a protracted operation, and it was over pretty quickly," Piringer said.

Both workers were treated at a local hospital and released.

Stay with NBCWashington on-air and online as this story develops.