One Iranian aid agency said 70,000 people needed shelter after the quake, one of the largest this year.
Most of those who died were in Iran’s western Kermanshah province. Nearly 6,300 are said to have been injured.
Seven people died in Iraq, where people fled into the streets in the capital, Baghdad.
“I was sitting with my kids having dinner and suddenly the building was just dancing in the air,” a Baghdad mother-of-three, Majida Ameer, told Reuters news agency.
“I thought at first that it was a huge bomb. But then I heard everyone around me screaming: ‘Earthquake!'”
In the latest updates from Iran:
State news agency Irna quoted an emergency official as saying 5,953 people were injured in Iran alone
Most of the victims were in the town of Sarpol-e Zahab, about 15km (10 miles) from the border, emergency services chief Pir Hossein Koolivand said
The town’s main hospital was severely damaged, leaving it struggling to treat hundreds of wounded, state TV reported
A woman and her baby were pulled alive from rubble in the town, Iranian media said.
Rescue teams were being hampered by landslides, Mr Koolivand said.
The quake hit at 21:18 local time (18:18 GMT) about 30km southwest of Halabja, near the northeastern border with Iran, the US Geological Survey (USGS) said.
About 1.8 million people live within 100km (60 miles) of the epicentre, the UN estimates.
On the Iraqi side, the most extensive damage was in the town of Darbandikhan in the Kurdistan Region.
“The situation there is very critical,” Kurdish Health Minister Rekawt Hama Rasheed told Reuters.
The Iraqi ministry of health said 321 people had been wounded in the Iraqi Kurdistan region, where Turkey has already delivered aid.
The BBC’s Rami Ruhayem, in the regional capital Irbil, said shaking there had lasted for more than a minute.
“For a few seconds at first it was barely detectable, I wasn’t sure whether it was a minor tremor or just my imagination,” he said. “But soon enough it was unmistakable as the building started swaying from side to side.”
The earthquake struck at a relatively shallow depth of 23.2 km, and tremors were felt in Turkey, Israel and Kuwait.
In 2003, a 6.6-magnitude quake destroyed the historic city of Bam in south-east Iran, killing 26,000 people.
Sunday’s quake is the deadliest to hit Iran since 2012.