MAIDUGURI, Nigeria — Militants attacked an army detention center in this northeastern Nigerian city in an attempt to free fellow Islamists who were held there, a military spokesman said Friday.

“The attack has been successfully repelled with heavy human casualty on the terrorists,” and troops are now pursuing the fleeing militants, Major-General Chris Olukolade said in an emailed statement. “Many of the terrorists and their weapons have been captured” while four soldiers were wounded. Casualty details will be provided later, he said.

Nigeria’s security forces are battling to contain the Islamist militant group Boko Haram, which has carried out a violent campaign since 2009 to impose Shariah, or Islamic law, in Africa’s biggest oil producer. Boko Haram attacks, concentrated mainly in the northeast of the country, haven’t eased since President Goodluck Jonathan imposed a state of emergency in Borno, Yobe and Adamawa states in May last year.

A group of fighters passed through Maiduguri’s GRA district at dawn and attacked the city’s Giwa Military Barracks with guns and explosives, Kamil Ibrahim, a resident, said by phone. Friday’s attack is a response to recent military offensives on Boko Haram camps.