There were no reports of deaths or serious injuries.
Parts of the White House, Capitol and Pentagon were evacuated. Two nuclear reactors at the North Anna Power Station in the same county as the epicenter were automatically taken off line by safety systems around the time of the earthquake.
The earthquake was centered near Louisa, Va., which is northwest of Richmond. It was among the largest earthquakes ever in Virginia. In 1897, a magnitude-5.9 quake was recorded at Giles County, Va., the largest on record in that state. The largest East Coast quake on record was a 7.3 that hit South Carolina in 1886.
The U.S. Geological Survey said the quake was 3.7 miles beneath the surface. The quake sent hundreds of people spilling into the street a block from the White House.
"When you have an earthquake on the East Coast, it's felt much more strongly than if we'd had one here in California, the way the geology is," said Caltech seismologist Anthony Guarino.
"The rocks on the East Coast are a better transmitter of energy than the rocks here on the West Coast," Caltech seismologist Dr. Lucy Jones said. "Out here they're relatively young and they're broken up by fault. Out there they're very intact, and an intact bell rings more loudly than a cracked bell."
Obama and many of the nation's leaders were out of town on August vacation when the quake struck at 1:51 p.m. EDT. The shaking was felt on the Martha's Vineyard golf course as Obama was just starting a round.
Manhattan District Attorney Cyrus Vance was holding a press conference regarding the dismissal of charges in Dominique Strauss-Kahn's sexual assault case when the earthquake struck, sending people running.
At the Pentagon, many people left the building to gather at their fire-alarm locations. Pentagon police said safety officers walked around the building and determined that the building was safe, and everyone who had gone outside was requested to come back into the building.
All buildings in the Capitol complex were evacuated as structural engineers inspected the buildings.
The Washington Monument was closed after the U.S. Park Service found cracks.
Twitter lit up with reports of the earthquake.
"People pouring out of buildings and onto the sidewalks and Into Farragut Park in downtown DC...," tweeted Republican strategist Kevin Madden.
"did you feel earthquake in ny? It started in richmond va!" tweeted Arianna Huffington, president and editor-in-chief of the Huffington Post Media Group.
Missouri Sen. Claire McCaskill tweeted that her staff in Washington was in an "emergency location. Hope everyone is ok."
According to a tweet from Washington Buisness Journal reporter Sarah Krouse, at least three pinnacles from the central tower at the National Cathedral broke off in the quake.
The National Cathedral said its central tower and three of its four corner spires were damaged.
Since the initial earthquake, at least a half dozen aftershocks were felt in Virginia, according to Amanda Reidelbach, spokesman for the Louisa County Department of Emergency Services in Mineral, Va. One of them was a 4.2-magnitude quake.
It was earlier reported that the earthquake was a 5.9, but it has since been downgraded to a 5.8.
The Associated Press contributed to this story.