Saudi Arabia says a raid targeting suspected Islamic State militants near the holy city of Mecca saw security forces shoot and kill two people while two others blew themselves up with suicide belts.

The raids on Thursday marked the first time Saudi officials have acknowledged targeting the kingdom's Islamic State affiliate near the city that is home to the Kaaba, the holy cube-shaped shrine of Islam toward which its faithful pray. It comes ahead of this year's hajj pilgrimage in September.

An Interior Ministry statement says the raid was carried out to halt an imminent attack, without elaborating. It said no security personnel or civilians were wounded.

In 1979, extremists held Mecca's Grand Mosque, home to the Kaaba, for two weeks as they demanded the royal family abdicate the throne.