The men were working at a derelict school site, on Daniel Hill, in the Upperthorpe area of Sheffield, when the ground collapsed beneath them.
Around 30 firefighters helped rescue the pair during a dramatic one-and-a-half-hour operation.
A South Yorkshire Fire and Rescue Service spokesman said both men were taken to hospital with injuries which were not believed to be life-threatening.
Another workman at the site raised the alarm at around 11.15am when he heard the men shouting for help from the well.
Six fire crews, from Sheffield and Rotherham fire stations, and a specialist technical rescue unit attended the accident.
A firefighter was lowered into the well to bring the men to safety using specialist rescue equipment.
Both men were conscious after they were removed from the well and were treated at the scene by paramedics before being taken to hospital.