KABUL, Afghanistan — Insurgents wearing police uniforms and vests laced with explosives stormed a police compound in eastern Afghanistan early Sunday morning, engaging in a firefight that lasted several hours before Afghan and NATO forces regained control of the complex, government officials said.

Three police officers and two Afghan National Army soldiers were killed in the attack, which occurred about dawn. A civilian who was walking by the compound was also wounded and died at a hospital, officials said.

The attack occurred in Khost, a volatile province bordering the tribal areas of Pakistan that have served as a haven for militants crossing into Afghanistan. It followed a pattern of assaults this spring in which insurgents wearing Afghan military or police uniforms have struck fortified government compounds. On Saturday, a suicide bomber who was believed to be wearing an army uniform blew himself up in a tent on the grounds of the national military hospital in Kabul, the capital, killing 6 people who were training to be medics and wounding more than 20 others.

The attack on Sunday, about a mile east of the city of Khost, the provincial capital, began when a group of men in Afghan Border Police uniforms rushed out of a station wagon and toward a traffic police building, killing the guard at the gate, said Abdul Jabar Naeemi, the governor of Khost Province.