In a statement read on state television, the ministry said that three cells had planned the attack on worshippers and security forces at the mosque as the Muslim holy month of Ramadan nears its end.
The trapped would-be suicide bomber exchanged fire with the security forces on Friday, then set off explosives when he was surrounded in a house in a central Mecca neighborhood, the ministry said, Reuters reported.
The building collapsed, injuring six foreigners and five members of the security forces.
Earlier in the day, security forces had shot dead a wanted man at another suspected militant hideout in Mecca's al-Aseelah neighborhood.
The ministry also said a third cell had been broken up in the Red Sea city of Jeddah, but gave no further details.
Five suspected militants including a woman were arrested, it said.
The month of fasting ends with the Eid-al-Fitr holiday, on Sunday. Saudi monarchs usually spend the last 10 days of Ramadan in Mecca.
The Grand Mosque houses Islam’s holiest site, the cube-shaped Kaaba that Islam's followers pray toward five times a day.
It was not immediately clear who was behind the plot to attack the mosque.