The Interior Ministry said it launched a raid around Jiddah, as well as two areas in Mecca itself, including the Ajyad Al-Masafi neighborhood, located near the Grand Mosque.
There, police said they engaged in a shootout at a three-story house a suicide bomber, who blew himself up and led to the building's collapse. He was killed while the blast wounded six foreigners and five members of security forces, according to the Interior Ministry's statement. Five others were arrested, including a woman, it said.
The blast demolished the building, its walls crushing a parked car as what appeared to be shrapnel and bullet holes peppered nearby structures.
The Interior Ministry "confirms that this terrorist network, whose terrorist plan was thwarted, violated, in what they would have perpetrated, all sanctities by targeting the security of the Grand Mosque, the holiest place on Earth."
More From This Section
"They obeyed their evil and corrupt self-serving schemes managed from abroad whose aim is to destabilize the security and stability of this blessed country," the statement said.
The disrupted attack comes at a sensitive time in Saudi Arabia as King Salman earlier this week short-circuited the kingdom's succession by making his son, Defense Minister Mohammed bin Salman, first in line to the throne. The newly appointed crown prince, 31 years old, is the architect of Saudi Arabia's war in Yemen against Shiite rebels, now stalemated. He has also offered aggressive comments about the kingdom confronting Shiite power Iran.
As the Interior Ministry announced the raid, over 1 million Muslim faithful prayed at the Prophet's Mosque in Medina to mark the end of Ramadan. In July 2016, a suicide bombing there killed four members of Saudi Arabia's security forces.
Millions of Muslims from around the world visit the mosque, the burial site of the Prophet Muhammad, every year as part of their pilgrimage to Mecca. The same day in July, separate suicide bomb attacks targeted a Shiite mosque in eastern Saudi Arabia and near the U.S. Consulate in Jiddah.