A Potomac Electric Power Co. transformer near the Southwest Washington riverfront exploded and burned yesterday afternoon, cutting power to 13,000 homes and businesses in Northwest, Bethesda and Chevy Chase for 2 1/2 hours. Thousands of homeward-bound commuters were inconvenienced as traffic lights went out and the Metro subway system was shut down at three stations north of Dupont Circle.

In the White House, the power outage briefly trapped President Reagan in an elevator on his way from the Oval Office to the State Dining Room to make an announcement on health care. Later as he prepared to return to his office he said, "I believe I'll take the stairs. I need the exercise."

When power went off at 2:35 p.m., the lights blinked out in the Van Ness subway station in Northwest Washington where a train was ready to unload. About 70 passengers were led out of the darkened station by Metro police and station workers with flashlights.

After that, homeward-bound subway commuters on the Red Line toward the Van Ness station had to leave the subway at Dupont Circle, where they were taken by emergency bus service north along Connecticut Avenue. By 4:55 p.m., trains were again running north and taking passengers to the stations at Woodley Park-Zoo, Cleveland Park and Van Ness.

Power went out as Pepco computers, in a 10-second period, shut down service along a wide swath from Buzzard Point in Southwest Washington, where the 235,000 volt transformer exploded, to Bethesda. The computers followed a preprogrammed emergency scenario designed to reduce load on the system by cutting power to selected customers.

A company spokesman said this had to be done to avoid a snowballing, uncontrolled shutdown of the entire Pepco system, which serves all of the District of Columbia and suburban Maryland. The customers whose power was cut were selected because the damaged transformer fed electricity in their direction, not because they would be shut down first in other emergencies, the spokesman said.

Power was not cut to designated critical customers such as hospitals, the spokesman said. He said there were no injuries as a result of the transformer explosion or power outages.

The transformer, in a power substation at Buzzard Point, exploded about 2:20 p.m. when a heavy oil expansion tank fell from the top of the transformer and crashed 20 feet to the ground, according to a witness. Fire and smoke were seen from across the Anacostia River, according to D.C. Fire Department Sgt. William J. Kelly.

"It sounded like dynamite. It scared the hell out of me. Fire and smoke was all over the place," said Aaron Pratt, a security guard at the substation, one of about 140 in the Pepco system that transforms massive voltages of electricity to smaller amounts for distribution along feeder lines to customers.

Firefighters had to wait about 15 minutes before attacking the blaze while Pepco operations officers, working in the totally computerized system control room in Montgomery County, studied the effects of the explosion and decided how to deal with it. Then they activated computers that started the shutdown of power to customers at 2:35.

The Pepco spokesman said that power was restored to all customers by 4:55.

Despite the general discomfort of being out of doors in the 88-degree heat and 65 percent humidity, subway passengers forced to leave the Metro system for buses at Dupont Circle said they were inconvenienced little if at all.

"Where I come from, you can't even get around this well," said Bob Hodges, a highway engineer from Frankfort, Ky., who was waiting for the shuttle bus at 20th and Q streets NW. Hodges, who said he was in the city attending a course for engineers at the U.S. Department of Transportation, smiled and explained: "I just have to get back to my hotel anyway."

Some, however, were not pleased by Metro's handling of the disruption, complaining they were not adequately instructed about how to complete their trips.

"They spent many minutes announcing on the subway that there was a power failure," said Bob Coffren, a business manager in Silver Spring who was on his way to a dental appointment. "But nobody thought to mention that you had to get out at 20th and Q to catch the bus. Like many others, Coffren had gotten out at the station's other exit, and had to walk across the circle to find the bus.

The buses ran between the Van Ness and Dupont Circle stations continuously. Delays were minimal.

Don Davis who also took the bus from Dupont to Van Ness said, "I was supposed to be at work at 5 o'clock and here it is 5:15." Davis, a cashier at the Van Ness Giant, fidgeted in his seat. "They're pretty strict about being on time," he said. "I hope they'll be good about it."

A Metro spokesman said that when the power outage occurred, the three Red Line stations lost power for lights, fare gates, escalators, elevators and signals. Emergency lights were switched on for the platforms, but the escalator areas were dark, the spokesman said.

At the time of the outage, there were two trains in the affected segment of the rail system north of Dupont Circle, the spokesman said. The trains themselves continued to have power because their electricity comes from a separate system that was not affected by the Buzzard Point incident. One of the trains continued to Dupont Circle and onward from there without incident, while the other stayed at Van Ness after letting off its passengers in the dark.

Traffic lights were out in scattered patterns throughout the affected area. Some lights continued to function since they receive power from feeder lines not affected.

According to a Pepco spokesman, the company could have cut power a little bit throughout the entire system--called a "brownout"--but decided against this for technical reasons. Instead, they decided on a computer program that dropped the selected customers in the Northwest Washington-Bethesda corridor where the damaged transformer had fed its power.

Within 10 seconds, the computer dropped 100 megawatts of power from the system. Then, gradually, the operations officers were able to reconstruct the system to function around the damaged transformer to restore power to affected customers.