The evening call to prayer could be heard as hundreds anxiously waited in the city’s Ita Faji area, trying to help in rescue efforts.
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.
“I’m extremely saddened by the news of the collapsed building in Ita Faaji area of Lagos.
“It touches one to lose precious lives in any kind of mishap, particularly those so young and tender.
“May God grant everyone affected by this sad incident fortitude and succour.”
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 went silent 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.
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 governor 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”.
Mr Ambode said: “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.”
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.”