The Interior Ministry said five militants were killed and four arrested when the military and police raided a bomb and weapons storage facility.
The fighters belonged to Ansar Bayt al-Maqdis, one of Egypt's most active militant organisations, the ministry said.
Security sources said gunfire erupted during a raid on a militant safe-house where the men were hiding in Qalubiya province, north of Cairo.
They said an army colonel and brigadier general, both bomb disposal experts, were killed.
Islamist militants based in the Sinai peninsula near Israel's border have stepped up attacks on security forces since the army toppled President Mohamed Mursi of the Muslim Brotherhood last July. About 300 security officers have been killed.
Ansar Bayt al-Maqdis has claimed responsibility for several high-profile attacks, including the bombing of a tourist bus in the Sinai last month that killed two South Koreans and an Egyptian.