A five-story apartment building that had been earmarked for destruction as an earthquake risk collapsed in Istanbul early Wednesday, killing two people and injuring 26, authorities said.

Rescuers called off a search by midday after ensuring that everyone was removed from the rubble. Heavy machinery was brought in to clear the debris. At least 27 people had been living in the building, Istanbul Gov. Muammer Guler said.

Some of the injured were customers of a coffee shop in the building's basement. The shop's owner and a passer-by realized the building was starting to crumble after midnight and alerted residents by ringing the bells, shouting and throwing pebbles at the windows and saving many lives, authorities said.

Rescuers pulled out a woman's body from the rubble, and another woman died of her injuries at a hospital, the office of Istanbul Mayor Kadir Topbas said.

Rescuers had reported that a 7-year-old girl was pulled out dead, but when she was taken to hospital, doctors said she was alive though barely breathing, Guler said. "She is alive and connected to a respiration machine." The state-run Anatolia news agency said she was in critical condition.

Guler said 26 people were hospitalized, including some who escaped from the coffee house.

Some people who had not managed to escape when the building began to crumble were injured and were trapped in a stairway — some for 45 minutes before being rescued, Istanbul fire department chief Ali Karahan said. ...

Ilhan Karadeniz, the owner of the coffee shop, said he woke up his neighbors when he noticed that the building was shaking.

"I was doing cleaning when I heard columns crumbling, I quickly rushed out and began ringing the bells," private Dogan news agency quoted Karadeniz as saying.

Idris Gunes, an injured survivor, left the building upon hearing the warnings.

"When we heard them, we rushed out," she told NTV television. "Everybody was in a panic and trying to help each other," she said. "But some people could not leave in time."

Teams — helped by sniffer dogs — had worked under floodlights to determine whether more people were trapped under the rubble of the building in residential Zeytinburnu district. Rescuers pulled away pieces of concrete with their bare hands and with the help of excavators.

Media reports suggested that the building's foundations might have been weakened by an adjacent construction. The city mayor confirmed the building had been listed as unsafe and earmarked for destruction as an earthquake risk.

Turkish rescuers often carry out earthquake drills in Istanbul to test the earthquake preparedness of this sprawling city of more than 12 million, which experts believe could be hit by a huge quake sometime in the next 30 years. Hours after the building collapsed in Zeytinburnu district, a moderate earthquake with a preliminary magnitude of 5.9 shook southeastern Turkey sending people into the streets in panic and damaging some buildings, officials said. No injuries were reported.

The epicenter was 750 miles southeast of Istanbul.

Geologists have urged the Turkish government since 1999 — when two earthquakes west of Istanbul killed more than 18,000 people — to tear down some 50,000 buildings that would probably collapse if a big quake hit Istanbul.

They say hundreds of thousands of other buildings that rise in an unstable mass of brick, mortar and stone, need to be reinforced.

Topbas said the collapsed building was on the list of 16,000 other buildings designated as needing to be pulled down in Zeytinburnu district alone.

Shoddy construction was blamed for many of the deaths in the 1999 quakes. Several contractors who were charged with negligence for ignoring building codes escaped punishment this week when statute-of-limitations expired in all ongoing cases that were filed in 1999.