Four security officers have been killed and five others wounded in a suicide attack outside one of Islam's holiest sites, Saudi Arabia's interior ministry said.

The bombing at the Prophet's Mosque in the city of Medina was the third attack to hit the kingdom on Monday, following blasts in the cities of Jeddah and Qatif.

Photos of Medina posted on social media showed smoke billowing from a fire outside the mosque where Prophet Muhammad is buried.

"Four security guards were martyred and five others wounded as a result of their opposition to the suicide attacker who detonated explosives near them as he was on his way to the mosque," the ministry said on Twitter.

The blast struck moments before sunset prayers when people were breaking their fast inside the mosque.

The mosque, which is also known as Al-Masjid an-Nabawi, is visited by pilgrims from around the world during the final days of the fasting month of Ramadan.

Qari Ziyaad Patel, 36, from South Africa, was at the mosque when he heard the blast just as the call to prayer was ending.

He said many at first thought it was the sound of traditional, celebratory cannon fire, but then he felt the ground shake.

"The vibrations were very strong," Patel told the AP news agency. "It sounded like a building imploded."

Saudi Arabia's state-run news channel, Al-Ekhbariya, broadcast live video of thousands of worshippers praying inside the mosque hours after the explosion.

The mosque is considered to be Islam's second holiest site after the Sacred Mosque, or Masjid-al-Haram, which surrounds the Kaaba in the city of Mecca.

READ MORE: Muslim world reacts after deadly blast

Following the attack in Medina, Muslims around the world expressed their outrage.

Iran's Foreign Minister Javed Zarif, writing on Twitter, said: "There are no more red lines left for terrorists to cross. Sunnis, Shiites [Shias] will both remain victims unless we stand united as one."

Mohammed bin Zayed Al Nahyan, the Crown Prince of Abu Dhabi, tweeted: "It's time we work together to save our religion from these deadly criminal gangs."

Qatif explosions

About the same time as the Medina blast, two other explosions struck near a mosque in the eastern city of Qatif on the Gulf coast.

Witnesses said a suicide bomber blew himself up outside a Shia mosque without injuring anyone else.

They reported seeing body parts lying on the ground in the city's business district.

"Suicide bomber for sure. I can see the body" which was blasted to pieces, a resident told the AFP news agency.

Nasima al-Sada, another resident, said "one bomber blew himself up near the mosque".

A third witness told Reuters news agency that one explosion destroyed a car parked near the mosque, followed by another explosion just before 7pm local time.

There was no claim of responsibility for the attacks.

Earlier on Monday morning, two security officers were injured as a suicide bomber blew himself up near the United States consulate in the Red Sea port city of Jeddah.

Security officers became suspicious of a man near the car park of Dr Suleiman Faqeeh Hospital which is directly across from the US diplomatic mission. When they moved in to investigate, "he blew himself up with a suicide belt inside the hospital parking", the interior ministry said.

Saudi's interior ministry identified the attacker as Abdullah Waqar Khan, a Pakistani national in his early 30s. In a tweet, the ministry said that Khan, a driver, had moved to Jeddah 12 years ago to live with his wife and her parents.

Pakistan said on Tuesday that it was going to investigate whether the suicide bomber in Jeddah was one of its nationals.

"We will investigate the claim that one of the bombers was a Pakistani who according to reports was living in Saudi Arabia for more than 12 years," a foreign ministry official told the DPA news agency on condition of anonymity.

In January, at least four people were killed in a suicide attack on a Shia mosque in the eastern al-Ahsa region.

In October, the Islamic State of Iraq and the Levant (ISIL) group claimed responsibility for a suicide bombing at a Shia mosque in Najran, in which at least one person was killed.

ISIL, also known as ISIS, also claimed responsibility for an attack at a mosque inside a special forces headquarters in the city of Abha in August 2015. Fifteen people were killed in that attack.