At least 31 people have been killed and 169 injured in an explosion at a mosque during Friday prayers in Pakistan's capital, Islamabad, officials say.

According to police, a suicide bomber detonated a device after approaching the gates of the Shia mosque in the Tarlai area of the city. Eyewitnesses have told the BBC the blast was preceded by the sound of gunfire.

An emergency was declared as hospitals began to receive the wounded, with an appeal sent out for blood donations.

Condemning the incident, Pakistan's Prime Minister Shehbaz Sharif expressed deep grief as he called for a thorough investigation and the immediate identification of those behind the attack.

In separate statements, Pakistan's President Asif Ali Zardari said targeting innocent civilians is a crime against humanity, while Defence Minister Khawaja Asif suggested India and Afghanistan were behind the attack.

Asif said in a social media post that it had been proven the attacker had travelled to and from Afghanistan, and collusion between India and Afghanistan is being revealed.

Afghanistan's Taliban government described Khawaja Asif's comments as regrettable, saying the Pakistani minister hastily attempted to attribute the incident to Afghanistan without presenting any credible evidence.

The Indian foreign ministry also condemned the attack and sent condolences for the loss of life, calling the accusations it may be involved baseless.

Talal Chaudhry, Pakistan's minister of state for interior, said the suspect was not an Afghan citizen, according to local media.

A spokesperson for United Nations Secretary-General Antonio Guterres condemned the attack in the strongest terms and called for those responsible to be identified and brought to justice.

During the dire moments inside the mosque, a participant named Zaheer Abbas recalled hearing gunfire followed by an explosive blast. Images from the scene depicted chaos, with shoes scattered across the floor and glass debris littered around victims who were injured and in distress.

The blast is part of a troubling trend, as attacks have recently escalated in Pakistan, resulting in significant casualties. Last year was marked as one of the deadliest for the country as violence surged, particularly attributed to militant activities in regions like Balochistan.