Four security officers were killed and five others were wounded when a suicide bomber detonated his vest outside one of Islam's holiest sites.
The Monday evening attack took place as thousands of worshippers were about to hold sunset prayers in the mosque where the Prophet Muhammad is buried in Medina.
The mosque is visited by millions of Muslims from around the world annually performing pilgrimage in Mecca.
The interior ministry said the attacker set off the bomb after security officers raised suspicions about him.
The attack took place in a car park outside the sprawling mosque complex.