It claimed one of the men killed at a checkpoint east of the capital had been responsible for the militant group's operations in the Cairo region.
Ansar Beit al-Maqdis (Partisans of Jerusalem), which has allied itself to the Islamic State group, is based in the Sinai Peninsula, and claims to be behind most of the major attacks on the security forces since the army ousted elected Islamist president Mohamed Morsi in July 2013.
Police spotted the jihadists' car at a checkpoint, the ministry statement said.
"The occupants of the car opened fire to try to get away, but the police fired back," it added.
"Three policemen and two civilians there by chance were injured" and the two jihadists were killed, it said.
Signup to our newsletter and follow us on Facebook and Twitter!
The ministry said the two men killed had taken part in several attacks on the army and the police, including one on November 28 in Cairo that killed a brigadier and a soldier.
Police also found guns and ammunition in an east Cairo apartment used by one of them.
Militants have killed scores of security personnel since Morsi was overthrown, saying the attacks are in retaliation for a brutal government campaign against his supporters.
The widespread crackdown has left at least 1,400 people dead and more than 15,000 jailed.
Most of the deaths occurred when police stormed two pro-Morsi protest camps in Cairo in August last year.
Hundreds more have been sentenced to death after perfunctory mass trials.