KABUL, Afghanistan — Unarmed police officers were lining up for their monthly pay in northern Afghanistan on Sunday when a Taliban suicide bomber blew up an explosives-laden Humvee next to a police compound, setting off a six-hour siege.

At least seven Taliban gunmen wearing police uniforms — some armed with suicide vests — rushed through a hole blown open by the explosion, police officials said. When the siege was eventually quelled, 20 police officers had been killed and 35 wounded, the officials said. Twenty civilians were also hurt, according to the Interior Ministry in Kabul.

By nightfall, police commanders said they had killed all attackers in the police headquarters in Pul-i-Kumri, the capital of Baghlan Province, about 150 miles north of Kabul. Bismullah Attash, a member of the Baghlan provincial council, said two of the uniformed attackers drove into the compound in private vehicles.

Abdul Qayoum Mubariz, a police officer based at the headquarters, said about 25 police officers — almost all of them unarmed — were waiting in line at a bank in the compound when the Humvee exploded. He said several soldiers were carrying plates of food from a dining hall as the attackers stormed inside.