Security forces pre-empted two planned terrorist attacks in Mecca's Assila district and Ajyad al-Masafi neighborhood, said Saudi Arabian Interior Minister, Mansour al-Turki.
"Unfortunately he started shooting towards security personnel once he noticed their presence in the area, which led to an exchange of fire before he blew himself up", Turki said.
Around 11 people, including six foreigners and five members of the security forces, were injured after the building collapsed.
Saudi officials said three terror groups had planned Friday's attack against the Grand Mosque: two based in Mecca and a third in the nearby city of Jeddah.
Another suicide bomber killed four security officers near the Prophet's Mosque in Medina in July 2016.
It can be recalled that the country faced an al-Qaida insurgency for years and attacks from a local branch of the Islamic State group.
The terror ring has been busted days after King Salman changed the Saudi accession order by making his 31-year-old son Mohammed bin Salman the Crown Prince of the Kingdom.
Earlier this month, Saudi Arabia and other Gulf states severed ties with Qatar citing Doha's support for terrorism - a charge the Qatari government denies.
At least 13 people were killed in an explosion at a mosque in the Asir region of southwestern Saudi Arabia in August 2015 and five more in an attack on a Shia mosque in Saihat, on the country's east coast.
The Supreme Council for Islamic Affairs in the Kingdom of Bahrain denounced the sinful terrorist plot to target the Grand Mosque in Makkah.
Al-Othaimeen added that no true Muslim would violate the sacredness of the holy mosque, particularly during the blessed month of Ramadan.
The Grand Mosque has been the target of militants before.
In 1979, a group of militants seized the mosque, home to the Kaabah, for two weeks as they demanded the royal family abdicate the throne.
Notwithstanding the political strain on its relationship with Saudi Arabia, Qatar said it would side with Saudi Arabia in all measures the kingdom would take to protect sacred places.
The Grand Mosque houses Islam's holiest site, the cube-shaped Kaaba that Islam's followers pray toward five times a day.