The man dug a roughly 10-foot-deep hole at Francis State Beach and was standing in it around 5:30 p.m. Monday when the sand started caving in around him, California Department of Forestry and Fire Protection Capt. Jonathan Cox said.
About 30 people, including the man's friends and bystanders, frantically dug with their hands, buckets and other improvised tools to expose his head. They were able to free his head in about five minutes, just as firefighters arrived at the scene, Cox said.
"When they got there, they discovered he was unconscious," he said.
Cox said paramedics managed to open his airways while about 30 firefighters, aided by the bystanders, used shovels and other equipment to pull out his body.
Rescuers extricated him in about 35 minutes and tried to revive him, but he died at the scene, Cox said.
The man who died at the beach about 30 miles southwest of downtown San Francisco was identified by the San Mateo County Coroner's office as Adam Pye, 26, of San Lorenzo.
He dug the hole on a campground area of the beach, about 10 to 15 feet from the water line, Cox said.