An unidentified man dangled upside down from a beam in a high-voltage electrical substation a few blocks from the Capitol last night, groaning in agony for more than two hours while rescuers prepared to free his severely burned body.

The harrowing incident apparently began about 9:30 p.m. at a substation near South Capitol and I streets SE, adjacent to Conrail railroad tracks that carry freight traffic along the southern edge of Capitol Hill.

Rescuers said it took about two hours before they could shut off power to the 12,000-volt substation and then make certain that the substation had been made safe for them to bring the man down.

Three rescuers in an aerial bucket extricated the man just before midnight. A helicopter flew him to the MedStar unit of the Washington Hospital Center. Witnesses said his clothing had been burned off. His condition was not immediately known.

Rescue workers at the scene said it appeared that after he entered the fenced and locked substation, the man, described by an Amtrak spokesman as an apparent trespasser, had been climbing in the network of beams, cables, transformers and insulators until he touched a live conductor. Then he fell, wedging his leg in the structure.

The ownership of the substation could not be clearly determined last night. An Amtrak spokesman said that it is used to lower the voltage of electricity that is supplied to Amtrak signals on nearby track running between Union Station and the 14th Street Bridge.

The spokesman said that Amtrak and Conrail trains that operate in the vicinity are diesel-powered.

Full details of the sequence by which power was cut off permitting the rescue were not immediately clear, but rescuers said they understood that power was switched off less than half an hour after the man was discovered. However, they said it took additional time for specialists to reach the scene and ensure that the substation was fully de-energized.

The substation is below the Southeast Freeway, about one-half mile south of the Capitol and about 100 yards east of South Capitol Street.

The site was invisible to motorists on the nearby roads, and traffic in the area flowed normally during the man's long ordeal.

Witnesses said the man flailed his arms and occasionally appeared to be trying to grasp the beam that wedged his foot.

The man was extricated at 11:50 p.m. by two employees of the Potomac Electric Power Co. and a District firefighter who were in an aerial bucket provided by the utility company.