Cairo (CNN) -- Hundreds of militants stormed a coastal Egyptian town riding on pickups and motorcycles, and shooting and throwing rocks at police and soldiers during clashes that left seven dead, officials said.

Among the fatalities in El-Arish on Friday was a 9-year-old boy who was shot while trying to take a picture with a cell phone, said Abdel Wahab, a doctor at the local hospital. Three military officers were also killed.

Thirty others were injured, officials said.

"The military attempted to withdraw to avoid bloodshed, but the armed men fired at them so they engaged, leaving the residents running for cover," said Hamdy Azzazy, a human rights activist who said he also got caught in the crossfire.

Some of the attackers were chanting slogans about Egypt returning to Sharia law.

"The attackers are Islamic extremists and they are heavily armed with machine guns, hand grenades and rocked-propelled grenades," said Gen. Saleh Al Masry, the head of security in North Sinai.

"The armed men attacked two police stations, and many soldiers and police officers have been injured while defending themselves. Three of the attackers were killed in the operation so far, " he added.

The town is on the Sinai peninsula about 340 kilometers (211 miles) northeast of Cairo.