Riyadh (AFP) - A deadly suicide bombing near Islam's second-holiest site in the Saudi city of Medina sparked condemnation across the Muslim world Tuesday, with even the Taliban and Hezbollah denouncing the attack.

Four people were killed in the explosion near the Prophet's Mosque that came as Muslims prepared for this week's Eid al-Fitr festival marking the end of the holy fasting month of Ramadan.

King Salman said Riyadh will hit hard those who seek to harm its young people, but in a speech also warned the kingdom's youth against "the dangers that lie in wait, notably extremism".

US National Security Council spokesperson Ned Price said: "Although the investigation of these attacks is still in its early phases, the intent of the terrorists is clear: to sow division and fear."

A spokesman for UN chief Ban Ki-moon also denounced the attacks.

"These crimes are all the more despicable as they were carried out as residents were preparing for Eid al-Fitr," Stephane Dujarric said.

The attack near the Medina mosque -- where the Prophet Mohammed is buried and which attracts millions of pilgrims each year -- was one of three in the Sunni-ruled Gulf nation on Monday.

There were no claims of responsiblity for the bombings in Medina, Jeddah and the eastern city of Qatif, but the Islamic State group had in May urged its supporters to carry out attacks during Ramadan.

The Sunni extremists have claimed or been blamed for a wave of shootings and bombings during Ramadan, including in Orlando, Bangladesh, Istanbul and Baghdad.

- Shock and outrage -

The Saudi interior ministry said officers became suspicious of a man heading for the mosque through a parking lot.

"As they tried to stop him, he blew himself up with an explosive belt causing his death and the death of four police," it said, adding that five others were wounded.

The targeting of Medina caused shock and outrage across Islam's religious divide.

Shiite power Iran called for Muslim unity and the Afghan Taliban branded it "gruesome".

Story continues

"There are no more red lines left for terrorists to cross. Sunnis, Shiites will both remain victims unless we stand united as one," Iranian Foreign Minister Mohammad Javad Zarif tweeted.

The Taliban said it "condemns this incident in the strongest of terms and considers it an act of enmity and hatred towards Islamic rituals".

Lebanon-based Shiite militant group Hezbollah -- which Riyadh accuses of supporting "terrorist acts" in the region -- also denounced it as "a new sign of the terrorists' contempt for all that Muslims consider sacred."

UN rights office spokesman Rupert Colville said: "It is an attack on the religion itself."

The head of the Saudi Shura Council, the main government advisory body, called the attack "unprecedented".

"This crime, which causes goosebumps, could not have been perpetrated by someone who had an atom of belief in his heart," Abdullah al-Sheikh said.

- 'Make us stronger' -

Cairo-based Al-Azhar, the highest authority in Sunni Islam, stressed "the sanctity of the houses of God, especially the Prophet's Mosque".

Middle East expert Madhawi al-Rasheed said the attack appeared aimed at humiliating Saudi Arabia, the guardian of Islam's holiest sites.

"It's an attempt to actually embarrass the Saudi government because it boasts of protecting the pilgrims and the holy places," said Rasheed, a visiting professor at the National University of Singapore.

At the same time as the Medina attack, another suicide bombing occurred near a Shiite mosque across the country in the Shiite-populated Gulf city of Qatif.

The interior ministry said "the body parts of three people were found" at the site but had not yet been identified.

Monday's first attack was in the western Saudi city of Jeddah, where two police officers were wounded in a suicide bombing near the US consulate.

The ministry said that attack was carried out by 35-year-old Pakistani Abdullah Qalzar Khan, who had been living in the city for 12 years.

The US embassy in Riyadh reported no casualties among consulate staff in the attack, which coincided with the US July 4 Independence Day holiday.

Saudi Crown Prince Mohammed bin Nayef, the interior minister, said while visiting wounded policemen in Jeddah the attacks "will only increase our solidarity and make us stronger".

Since late 2014 a series of bombings and shootings claimed by IS in Saudi Arabia has targeted minority Shiites as well as the security forces, killing dozens.

Most attacks have been in Eastern Province, home to the majority of Shiites in the country.

IS leader Abu Bakr al-Baghdadi has called for attacks on Saudi Arabia, which is taking part in the US-led coalition bombing the jihadists in Syria and Iraq. The group also considers Shiites to be heretics.