Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Several hundred inmates escaped after Taliban militants attacked a prison overnight, Afghan officials said.

The siege began when a suicide bomber detonated a device near the gate of the main prison in Ghazni at around 2 a.m. local time, Deputy Provincial Gov. Mohammad Ali Ahmadi told NBC News.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"Very well-armed and well-organized" militants followed closely behind, he said.

The assault sparked a firefight, which lasted almost an hour and left at least four police officers and three attackers dead. Seven other officers were injured in the attack, according to Ahmadi.

The Ministry of Interior said in a statement that 355 of a total 436 prisoners held at the facility escaped. While most of the inmates are ordinary criminals, 148 of those who fled were being detained for crimes against national security. The statement added that only three escapees had been recaptured.

Afghan security members stand guard on the roof of the main prison building in Ghazni after an attack on Monday. Rahmatullah Nikzad / AP

Most of the high-value prisoners were moved to a facility in Kabul earlier this year, a senior Interior Ministry official told NBC News.

A senior intelligence official confirmed that some inmates were moved to Kabul following fears that the Ghazni facility was vulnerable to an attack from militants.

A Taliban spokesman claimed responsibility for the attack in an email to media outlets. Dozens of fighters, including 10 suicide bombers, executed the ambush, Zabinullah Mujahid said. He also confirmed government reports that three Taliban attackers were killed in the siege.

"Security forces in the province have been deployed to the city and surrounding districts to recapture the escapees and militants involved in the attack," Ahmadi said. "An investigation is underway to determine all the facts."