KABUL, Afghanistan — Taliban fighters raided the main prison in the southern province of Ghazni early on Monday, freeing hundreds of inmates after detonating explosives at the entrance and killing police guards, Afghan officials said.

Sediq Sediqqi, the spokesman for the Afghan Ministry of Interior, said the attack began at 2 a.m., when the insurgents set off a car bomb, then killed four of the prison guards and wounded seven others in a shootout. The prison was being guarded by 48 police officers at the time of the attack, a member of the provincial council in Ghazni said.

“There were 436 prisoners in the jail; 351 of them escaped,” Mr. Sediqqi said. Of those who fled, 148 were Taliban prisoners, whom Mr. Sediqqi described as “terrorists on charges of national security crimes.”

Mr. Sediqqi said that 18 senior Taliban members in the prison had been moved to Kabul a day before the attack.