ANKARA, Turkey (AP) — A powerful 7.8 magnitude earthquake hit southeast Turkey and Syria early Monday, toppling buildings and sending panicked residents pouring outside in a cold winter night. At least 31 were killed, and the toll was expected to rise.

Rescue workers and residents using flashlights were searching through piles of tangled metal and concrete rubble in one of the stricken cities. People on the street shouted up to others inside a partially toppled apartment building, leaning dangerously.

The quake, felt as far away as Cairo, was centered north of the city of Gaziantep in an about 90 kilometers (60 miles) from the Syrian border. Along with several cities, the area is home to home to millions of Syrian refugees who fled their country’s long-running civil war. Turkey, which borders Syria to the north, hosts the largest number of Syrian refugees in the world.

On the Syrian side of the border, the quake smashed opposition-held regions that are packed with several million displaced Syrians with a decrepit health care system after years of war. At least 11 were killed in one town, Atmed, and many more were buried in the rubble, a doctor in the town, Muheeb Qaddour, told The Associated Press by telephone.

“We fear that the deaths are in the hundreds,” Qaddour said, referring to the rebel-held northwest. “We are under extreme pressure.”

Turkish President Recep Tayyip Erdogan said on Twitter that “search and rescue teams were immediately dispatched” to the areas hit by the quake.

“We hope that we will get through this disaster together as soon as possible and with the least damage,” he wrote.

There were at least 6 aftershocks, and Interior Minister Suleyman Soylu urged people not to enter damaged buildings due to the risks.

“Our priority is to bring out people trapped under ruined buildings and to transfer them to hospitals,” he said.

Tallies from various officials put the toll at at least 18 dead in Turkey and 13 in Syria. At least 130 buildings tumbled down in Turkey’s Malatya province, Gov. Hulusi Sahin said.

In northwest Syria, the opposition’s Syrian Civil Defense described the situation in the rebel-held region as “disastrous” adding that entire buildings have collapsed and people are trapped under the rubble. The civil defense urged people to evacuate buildings to gather in open areas. Emergency rooms were full of injured, said Rass.

The U.S. Geological Survey said the quake was centered about 33 kilometers (20 miles) from Gaziantep, a major city and provincial capital. It was centered 18 kilometers (11 miles) deep, and a strong 6.7 aftershock rumbled about 10 minutes later.

Syria’s state media reported that some buildings collapsed in the northern city of Aleppo and the central city of Hama.

In Damascus, buildings shook and many people went down to the streets in fear.

The quake jolted residents in Lebanon from beds, shaking buildings for about 40 seconds. Many residents of Beirut left their homes and took to the streets or drove in their cars away from buildings.

The earthquake came as the Middle East is experiencing a snowstorm that is expected to continue until Thursday.

Turkey sits on top of major fault lines and is frequently shaken by earthquakes.

Some 18,000 were killed in powerful earthquakes that hit northwest Turkey in 1999.