Authorities in Saudi Arabia have foiled a "terrorist action" targeting the Grand Mosque in Mecca, according to officials.

The Saudi interior ministry said in a statement on Friday that a man who planned to attack the mosque blew himself up when security forces surrounded a house in Mecca where he was hiding.

At least 11 people, including five policemen, were wounded in the collapse of a three-storey building where the suspect had barricaded himself, the ministry said.

Five other people, including one woman, were detained during the operation, it added.

Muslims from around the world converge to Mecca this time of the year for the conclusion of the holy fasting month of Ramadan.

Since late 2014, Saudi Arabia has faced periodic bombings and shootings claimed by the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group.

Purported images from the scene that circulated on social media showed an alley filled with bricks and other debris apparently from a blast.

Video showed what appeared to be a man's head lying among rubble from a collapsed structure.

Four people were killed last year days before the end of Ramadan in an explosion close to Islam's second holiest site, the Prophet's Mosque, in the city of Medina.

It was one of three suicide blasts around the kingdom on the same day, and which the US Central Intelligence Agency said bore the hallmarks of ISIL.

Source: News agencies