The temblor was centered 32 kilometers (20 miles) southwest of Halabja, Iraq, and had a depth of 33.9 kilometers (21 miles), the US Geological Survey said.
There were no immediate reports of casualties in Iraq.
The most extensive damage was in the town of Darbandikhan, 75 kilometers (47 miles) east of the city of Sulaimaniyah, and more than 30 people were injured in the town.
Two people have died in the city of Qasr-e Shirin, Iranian TV reported, citing the country's Emergency Services.
An quake measuring 7.2 on the Richter scale hit has Iraq's Sulaimaniyah province, killing four persons and injuring 50 others, the media reported.More news: ISIS leader Abu Bakr al-Baghdadi may be in Syria's al-Boukamal
Local media reported that eight villages in Iran had been damaged by the quake and rescue teams had been sent to those areas.
Many residents in the Iraqi capital of Baghdad and also in other cities including Irbil in the Kurdistan region rushed out of houses and buildings in panic.
"I felt like I was on a boat, I thought it was vertigo". The natural disaster struck along the border with Iran. But then I heard everyone around me screaming "Earthquake!"'.
Iraq's Meteorological Organization issued a warning on Iraqi State TV urging citizens to stay away from buildings and to refrain from using elevators.