BEIRUT, Lebanon — Security forces in Saudi Arabia thwarted a militant plot to carry out an attack near the Grand Mosque in the holy city of Mecca on Friday, according to the Saudi-owned Al Arabiya television, citing a statement by a spokesman for the Saudi Interior Ministry.

The authorities confronted militants in three places, one in the Red Sea port city of Jidda and two in Mecca, the statement said. After refusing to surrender, a suicide bomber near the Grand Mosque blew himself up, wounding five security officers and six bystanders.

The statement did not say whether the militants belonged to a specific group or what their ultimate target was. But the jihadists of the Islamic State group have harshly criticized Saudi Arabia and carried out a number of deadly attacks in the kingdom in recent years.

A successful militant attack in Mecca would be a blow to Saudi Arabia, which derives legitimacy in the Muslim world for its stewardship of the holy sites and whose monarch bears the title “custodian of the two holy mosques,” meaning those in Mecca and Medina.

The two cities are Islam’s holiest, and Mecca’s Grand Mosque houses the Kaaba, the black cube toward which the world’s Muslims pray.

While militants have not attacked Mecca in years, a suicide bomber blew himself up last year near the Prophet’s Mosque in Medina.

Security officials in Saudi Arabia and elsewhere have been on alert in recent days, worried that jihadists could stage attacks during the final days of the fasting month of Ramadan, which ends this weekend, or during the holiday that follows.