Emergency crews sifted through debris as night fell on frantic efforts to rescue scores of school children and others feared trapped inside a three-story building that collapsed Wednesday in Nigeria's densely populated commercial capital, Lagos. At least eight people were confirmed dead and 37 others were rescued alive.

Anguished families crowded around the flattened remains of the building holding out hope that more children would still be found alive in the wreckage. The collapsed building was a residential block containing a number of apartments as well as the school, according to BBC News.

Scenes of jubilation erupted earlier in the day when a man was brought out alive. But the mood shifted dramatically an hour later when another man was brought out dead. The rescue of a woman carried to an ambulance on a stretcher was greeted with cries of, "She's not dead!" in the local Yoruba language.

Rescue workers help carry a child at the site of a collapsed building containing a school in Nigeria's commercial capital of Lagos, Nigeria, on Wed., March 13, 2019. Reuters

The evening call to prayer could be heard as hundreds anxiously waited in the city's Ita Faji neighborhood trying to help in rescue efforts. Using flashlights, some people pulled what looked like clothing from the ruins. In the crowd, a baby cried.

Get Breaking News Delivered to Your Inbox

As many as 100 children had been in the primary school on the building's top floors, witnesses said.

"It touches one to lose precious lives in any kind of mishap, particularly those so young and tender," Nigerian President Muhammadu Buhari said.

Earlier, Associated Press video showed rescuers in yellow vests carrying dust-covered, stunned-looking children from the rubble, to cheers from hundreds who had rushed to the scene. But the crowd quieted as others were pulled out slung over rescuers' shoulders, unmoving.

The children were hurried to ambulances. One man pressed his hands to a passing survivor's head in blessing.

People spray water on a child who was rescued at the site of a collapsed building containing a school in Nigeria's commercial capital of Lagos, Nigeria, on March 13, 2019. Reuters

More equipment was brought in as nightfall approached. National Emergency Management Agency spokesman Ibrahim Farinloye said 37 people had been pulled out alive, while eight bodies were recovered from the ruins. An unknown number remained missing.

It was not immediately clear why the building collapsed, but such disasters are all too common in Nigeria, where new construction often goes up without regulatory oversight and floors are added to already unstable buildings.

Lagos state Gov. Akinwunmi Ambode said the building, which had been marked for demolition, was classified as residential and the school was operating illegally on the top two floors.

He promised a full investigation once rescue operations were concluded and vowed that those responsible would be prosecuted.

"I want to commiserate with the families of those that lost their lives in this collapsed building," the governor said in a post on his Facebook page that also urged onlookers to "give the rescue workers the chance to save more lives."

Mohammed Muftau, a resident who witnessed the collapse, told BBC News that the building had been cracking for long time and that complaints had been raised about it.

The children's rights group Plan International Nigeria called on the Lagos state government to "launch an inquiry into the incident, and ensure that all persons found culpable for dereliction of duties are punished."

"This incident has further highlighted the urgent need ... to take urgent action on issues of safety in schools across the country," country director Hussaini Abdu said.

Medics transport an injured person at a hospital after a building containing a school collapsed in Nigeria's commercial capital of Lagos, Nigeria, on March 13, 2019. Reuters

Ambode, the state governor, said his deputy was visiting hospitals and that the government would cover the hospital bills of survivors. "All we are interested in now is to save more lives and also see how those that have been rescued are put in proper place and proper care," he said.

Earlier in the day, anxious onlookers stood in narrow streets and on rooftops of rusted, corrugated metal, watching the rescue efforts. With emotions high, a number of shirtless men jumped in to offer assistance, hacksaws and mallets in hand. Some were barefoot. Some were bare-handed. One held a water bottle in his teeth.

The collapse came as Buhari, newly elected to a second term as president, tries to improve groaning, inefficient infrastructure in Africa's most populous nation.

In a recent report, the International Monetary Fund noted the state of the country's crumbling infrastructure.

"Nigeria's infrastructure is generally less than half the size than in the average sub-Saharan Africa country and only a fraction of that in emerging market economies," the report said. "The perceived quality of the infrastructure is low."