Muslim worshipers gather after a suicide bomber detonated a device near the security headquarters of the Prophet's Mosque in Medina, Saudi Arabia, on July 4. (Reuters)

The attack near the Prophet's Mosque in the Saudi Arabian city of Medina — the second holiest site in Islam — took place around sunset. The bomber reportedly sat with security guards as they were preparing to break their fast for Ramadan. Then he detonated his explosives, killing himself and the four security officers.

Thousands of people were gathered nearby to pray when the attack took place on Monday. Video on social media shows stunned worshipers taking out their cellphones to film the dark clouds of smoke that rose in the air from the explosion.

According to Saudi Arabia's Interior Ministry, four security officers were killed and five others wounded in the attack. It was the third such attack in Saudi Arabia that day. The others targeted a U.S. consulate and a mosque in a city where many of Saudi Arabia's Shiite minority residents live, but the attacker in Medina chose to detonate his explosives strikingly close to the 7th century mosque where the Islamic prophet Muhammad is buried. That particular suicide attack struck a sensitive chord with Muslims around the world because of the religious significance of the site to both Sunnis and Shiites.

Muslim leaders in Iran, Malaysia, Turkey and Egypt united to condemn the attacks, with some saying that they were an "assault on Islam itself." The Egyptian Foreign Ministry called the attacks "vile terrorism" in a statement, and Iranian Foreign Minister Mohammad Javad Zarif wrote on Twitter that "there are no more red lines left for terrorists to cross."

Despite their religious and traditional differences, both Shiites and Sunnis consider the Prophet's Mosque holy and historically significant. The site in Medina is one of three mosques that both of the main branches of Islam accept. It is said to contain the mosque that prophet Muhammad built in 622. It has undergone tremendous changes under different Islamic rulers and can now accommodate millions of pilgrims each year.

While Mecca is considered the holiest site in Islam, millions of Muslims making the hajj pilgrimage also visit the Prophet's Mosque in Medina, which contains his tomb as well as those of the first two caliphs (religious leaders), Abu Bakr and Omar.

Although no group immediately claimed responsibility for the attack, the suicide bombers are suspected of having links to the Islamic State. That supporters of a Sunni extremist group would choose to target a mosque that millions of Muslims consider holy and choose to do so during the last few days of the Muslim holy month of Ramadan makes it especially shocking. However, the Islamic State has destroyed mosques before and sees itself at odds with Saudi Arabia's ruling al-Saud dynasty and the country's religious authorities.

This isn't the first time terrorists have used religious spaces to achieve their political goals at holy sites in Saudi Arabia. In 1979, extremists stormed the Grand Mosque in Mecca, Islam's holiest site, and held 100,000 people hostage. Experts say the siege of the Grand Mosque led to a shift toward conservative Islam by the Saudi government and helped give rise to groups such as al-Qaeda. And some experts see parallels with how the Islamic State is adopting strategies similar to those of al-Qaeda, but point out that the Islamic State's ideology is different.

Read More: 

Can Saudi Arabia pivot away from oil? A powerful prince brings his pitch to America.