The city of Peshawar is close to the border with Afghanistan.
After the attack, the Pakistani authorities declared a maximum alert throughout the country.
Rescuers launched a frantic rescue operation to try to save people from beneath the rubble, after a wall of the mosque and part of the roof were destroyed.
“There are a lot of policemen buried under the rubble,” said Peshawar police commander Muhammad Ijaz Khan, who estimated that 300 to 400 officers usually attend the prayer.
An AFP journalist at the scene saw bloodied survivors emerge from the rubble.
“It is an emergency situation,” said Muhammad Asim Khan, a spokesman for Peshawar’s main hospital, adding that 47 people had been killed and 150 injured.
A vast rescue operation is underway at the site, launched by firefighters with the help of machinery to clear the rubble.
But by nightfall, there were at least four trapped men visible in the cracks, along with bodies that have not yet been removed.
“We gave them oxygen so they don’t have trouble breathing,” said Bilal Ahmad Faizi, a spokesman for the rescue agency 1122.
“They were screaming for help”
The authorities decreed a maximum alert in the capital and throughout the country. In Islamabad, snipers were placed to protect some buildings and at access points.
“The terrorists want to strike fear into those who are tasked with defending Pakistan,” Prime Minister Shehbaz Sharif said in a statement.