(Adds details, background)
By Lanre Ola
MAIDUGURI, Nigeria, March 14 (Reuters) - Heavy gunfire raged for two hours in Nigeria's northeastern city of Maiduguri on Friday morning, residents said, and explosions were heard at the Giwa barracks, where the army has detained hundreds of Islamist insurgent suspects.
Al Qaeda-linked Boko Haram has killed thousands in an almost five-year-long insurgency aimed at carving out an Islamic state in the religiously diverse country of about 170 million people.
"The sound of heavy gunfire and what sounds like RPGs (rocket propelled grenades) began at around 7:15 a.m. and it is still going," a Reuters witness said. The fighting was happening at Fori, an area near a military barracks, he said.
Boko Haram is the biggest security threat in Africa's top oil exporter and the continent's second biggest economy. More than 2,000 people have been killed in Boko Haram violence in the last six months, security sources say.
President Goodluck Jonathan intensified the military campaign almost a year ago to oust insurgents from their stronghold in the poor and undeveloped northeast but it has failed to stem the bloodshed.
Violence in recent months has mostly been confined to rural regions where Boko Haram often gains the upper hand against the military. An attack on the northeast's biggest city where there is a heavy army presence would be a setback for Jonathan.
Western governments are concerned about Boko Haram joining forces with al Qaeda affiliates operating in the Sahel. The unrest has already pushed thousands of refugees over the borders into neighbouring Niger and Cameroon. (Additional reporting by Isaac Abrak in Kaduna; Writing by Joe Brock; Editing by Louise Ireland)