Saudi Arabia on Sunday said police killed the man who planned a July attack on one of Islam's holiest sites, identifying him as a former scholarship student who abandoned his studies to join the Islamic State group in Syria.

The Interior Ministry said Taie bin Salem bin Yaslam al-Saya'ari died alongside another extremist in a shootout Saturday with officers in Riyadh, wearing a suicide bomb vest and clutching a machine gun.

It said he manufactured the suicide bomb used in the July 4 attack outside of the Medina mosque where the Prophet Muhammad is buried, an assault which killed four Saudi security force members and wounded five.

Millions of Muslims from around the world visit the mosque 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.

Al-Saya'ari previously was a scholarship student in New Zealand who quit school to travel to Syria and fight in the country's civil war, the ministry said. It said he later traveled to Turkey, Sudan and Yemen before returning to the kingdom.

The path of the other militant killed Saturday, Talal bin Samran al-Sa'aeidi, also showed the challenge faced in confronting the Islamic State group within the kingdom. He previously was arrested for fighting abroad and underwent counseling when he returned to the kingdom, the Interior Ministry said in a statement.

The militant threat from the Islamic State group is the most serious the kingdom has faced since battling an al-Qaida insurgency over a decade ago.