"The terrorists started shooting towards security forces, which they responded to", leading to the deaths of a pair of suspects while the others "committed suicide by blowing themselves up with suicide belts", the ministry's spokesman said in a statement.
Police had surrounded the suspects' hideout between the holy city of Mecca and the mountain resort of Taif, about 80 kilometres (50 miles) to the east, on Thursday morning when the shootout occurred.
A simultaneous raid occurred on a hideout in the Red Sea city of Jeddah, where two people were arrested, "and they are being investigated for their involvement in this cell", the spokesman said.
"The security operation is still underway. Explosives are being removed and the area combed. And the suicide belts, explosives and weapons at the first location are being dealt with," the spokesman said.
The raids were part of surveillance and followup, "including to what happened in Bisha on Friday".
At that time, two suspects died in a shootout with security forces who foiled a car bombing in Bisha, southwestern Aseer region.
A third suspect, Iqab Mujab al-Otaibi, fled but was later arrested wearing an explosives belt, the ministry announced last Sunday.
According to the ministry, Otaibi allegedly took part in a deadly shooting at a Shiite mosque in 2014 and a bombing at a mosque inside a Saudi special forces compound in the southwestern city of Abha last August.
Both attacks were among several bombings and shootings claimed by the ISIS of Sunni jihadists since late 2014 in Saudi Arabia.
ISIS also said it was responsible for shooting dead a Saudi police colonel in the Riyadh region last month.
ISIS considers Saudi Arabia's Shiite minority to be heretics.
The ISIS group leader, Abu Bakr al-Baghdadi, has reputedly called Saudi Arabia's Sunni rulers "apostate tyrants" and called on Saudis to rise against them.
The kingdom is part of the US-led coalition bombing ISIS in Iraq and Syria, and Saudi political and religious leaders routinely denounce ISIS attacks -- at home and abroad -- as contrary to Islam.
Still, a report last year by the inter-governmental Financial Action Task Force said Saudis comprised the second largest nationality among "foreign terrorist fighters" with ISIS.