There were no immediate reports of deaths or major damage.
The quake was felt across much of China and as far southwest as Bangkok, Thailand's capital, some 3,300 km (2,050 miles) away, where office buildings swayed for several minutes.
Premier Wen Jiabao was flying to Chengdu, a fast-growing metropolis of 10 million people and famous for its Giant Panda Breeding Research Base, state television said. President Hu Jintao had demanded that any injured are rescued immediately, Xinhua news agency said.
The city is around 1,300 miles southwest of Beijing.
"All the buildings are swaying back and forth," said a university student in the central city of Wuhan, adding that people had rushed outside and one single-storey building had collapsed.
"We felt continuous shaking for about two or three minutes," said another office worker. "All the people in our office are rushing downstairs. We're still feeling slight tremblings."
An employee at the local newspaper in Mianyang in Sichuan said there had been several earthquakes. USGS said there had been an aftershock of magnitude 6.0 at 2:43 a.m. EDT (0643 GMT) in roughly the same location and another at 3:34 a.m. EDT (0734 GMT) of magnitude 5.4.
One of China's tallest buildings, the Jinmao Tower in Shanghai, as well as other high-rise buildings were ordered evacuated after the quake and aftershocks. Office workers in some buildings were later allowed to return.
HOSPITAL EVACUATED
"The air-conditioning unit fell off the wall. Vases are all broken," a resident in Mianyang, in Sichuan province, told Reuters.
"The sick in hospital have been moved outside to open fields. There is no electricity and no mobile phone reception. People are afraid of aftershocks."
Many workers poured from their buildings in Beijing's financial centre after a second quake, or aftershock, measuring 3.9 on the Richter scale, jolted the eastern Beijing suburb of Tongzhou, but there were no visible signs of damage. The subway system was unaffected.
The U.S. Geological Survey said on its website (http://earthquake.usgs.gov) that the main quake struck at 2:28 a.m. EDT (0628 GMT) at a depth of 29 km (18 miles).
Sources said there was no immediate impact to the Three Gorges Dam project, the weight of whose massive reservoir, hundreds of kilometers from Chengdu, experts have said could increase the risk of tremors.
A source at the biggest refinery in western China, Lanzhou, said the plant also appeared unaffected by the quake.
An official with the Sichuan provincial seismic bureau said the epicenter of the quake was in Wenchuan county, in the Aba Tibetan and Qiang Autonomous Prefecture, a mountainous area populated mostly by Han Chinese but with sizeable Qiang and Tibetan populations.
RESCUE TEAMS READY
On Chinese state television, a reporter said that telephone calls to Wenchuan were not connecting. State TV also said the government was preparing to send rescue and aid teams to the region.
A receptionist at the Tibet Hotel in Chengdu said the hotel had evacuated its guests, but said things were "calm" there now. "It was very sudden and I am not sure what has happened elsewhere, but we are OK here," the receptionist said.
The quake was felt as far away as Vietnam and Thailand, startling office workers in high-rise buildings.
"We have a number of reports that high buildings along Sukhumvit and Sathorn roads (in Bangkok) felt the tremors, but there are no reports of damage," a geologist at Thailand's Meteorological Department told Reuters.
High-rise residential and office towers in the western suburbs of Vietnam's capital, Hanoi also shook for several seconds, witnesses said, but there was no visible damage. Hundreds of residents and office workers left the buildings as a precaution.
(Reporting by Jason Subler and Darren Schuettler; Writing by David Fox; Editing by Jeremy Laurence)