A 7.3 magnitude earthquake near the Iraq-Iran border has killed more than 400 people and sent residents fleeing their homes into the night, authorities said.
Iran's western Kermanshah province bore the brunt of the quake on Sunday night, with authorities saying the quake killed 407 people in the country and injured 6,700.
Kermanshah is a rural, mountainous region where residents rely mainly on farming.
In Iraq, the earthquake killed at least seven people and injured 535, all in the country's northern Kurdish region, according to Iraq's Interior Ministry.
The quake was centred 19 miles (31km) outside the eastern Iraqi city of Halabja, according to the most recent measurements from the US Geological Survey.
It struck at 9.48pm Iran time, just as people began retiring for the night.
It could be felt on the Mediterranean coast, some 660 miles (1,000km) away.
The earthquake struck 23.2km (14.4 miles) below the surface, a shallow depth that can amplify damage.
Iranian social media and news agencies showed images and videos of people fleeing their homes. More than 100 aftershocks followed.
The quake's worst damage appeared to be in the town of Sarpol-e-Zahab in Kermanshah province, which sits in the Zagros Mountains that divide Iran and Iraq.
Kokab Fard, a 49-year-old housewife in Sarpol-e-Zahab, said she fled empty-handed when her apartment complex collapsed.
"Immediately after I managed to get out, the building collapsed," she said. "I have no access to my belongings."
Sarpol-e-Zahab residents said the power and water were out and telephone and mobile phone lines were spotty.
Iran's Supreme Leader Ayatollah Ali Khamenei offered his condolences this morning and urged rescuers and government agencies to do all they could to help those affected, state media reported.
President Hassan Rouhani is scheduled to tour earthquake-damaged areas tomorrow.
The semi-official ILNA news agency said at least 14 provinces in Iran had been affected by the earthquake.
Behnam Saeedi, a spokesman for the country's crisis management headquarters, told two semi-official news agencies that casualty figures stood at 407 killed and 6,700 injured.
In Iraq, Prime Minister Haider al-Abadi issued a directive for the country's civil defence teams and "related institutions" to respond to the natural disaster.
The quake could be felt across Iraq, shaking buildings and homes from Irbil to Baghdad, where people fled into the streets of the capital.
Amina Mohammed, who survived the quake in Darbandikhan, Iraq, said she and her sons escaped their home as it collapsed around them.
"I think it was only God that saved us," she said. "I screamed to God and it must have been him who stopped the stairs from entirely collapsing on us."
The Iraqi city of Halabja, closest to the epicentre, was the target of a 1988 chemical attack in which Saddam Hussein's troops killed some 5,000 people with mustard gas - the deadliest chemical weapons attack ever against civilians.
Iraqi seismologist Abdul-Karim Abdullah Taqi, who runs the earthquake monitoring group at the state-run Meteorological Department, said the main reason for the lower casualty figure in Iraq was the angle and the direction of the fault line.
He said the Iraqi geological formations were better able to absorb the shocks.
However, the quake caused visible damage to the dam at Darbandikhan, which holds back the Diyala River.
"There are horizontal and vertical cracks on the road and in the body of the dam, and parts of the dam sank lower," said Rahman Hani, the director of the dam.