Yesterday's attacks on Islam's spiritual home came as Muslims prepare for the feast this week marking the end of the holy fasting month Ramadan.
There were no claims of responsiblity, but the Islamic State group had urged its supporters to carry out attacks during the holy month and has claimed or been blamed for a wave of Ramadan shootings and bombings including in Orlando, Bangladesh, Istanbul and Baghdad.
The Saudi interior ministry said in a statement that security forces became suspicious of a man who was heading for the Prophet's 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 security personnel," the statement said, adding that five others were injured.
Also Read
The targeting of Medina caused widespread outrage.
Cairo-based Al-Azhar, the highest authority in Sunni Islam, condemned the attacks and stressed "the sanctity of the houses of God, especially the Prophet's Mosque."
Interior ministry spokesman General Mansour al-Turki told state news channel Al-Ekhbaria that the bomber was closer to a mosque in the area than to the consulate.
The ministry said in the statement published on the official SPA news agency that the bomber's explosive belt had "partially" exploded.
The head of Saudi Arabia's Shura Council, the kingdom's main advisory body, said the attack was "unprecedented".
Iran, the main Shiite power, also condemned the bombings and called for Muslim unity against extremists.
"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 said on Twitter.
The US embassy in Riyadh reported no casualties among consulate staff. The attack coincided with the US July 4 Independence Day holiday.