The Ivory Coast's government and mutinying troops have reached a final deal at talks in Bouake, government sources said, shortly after talks were interrupted by gunfire at barracks across the country.

Hours before the agreement, troops sealed off the northern city of Korhogo and the second largest city, Bouake, where they surrounded the building in which the defence minister was negotiating the deal. However, he left the talks unharmed.

"A deal has been reached in Bouake between the chief of staff, the defence minister and the troops," a source close to the presidency told AFP late on Friday.

READ MORE: Ivory Coast minister freed after troops mutiny deal

Several of the rebelling soldiers also confirmed that a deal had been struck, with one telling AFP: "We are pleased, we've reached an agreement".

Soldiers in Bouake mutinied earlier this month, firing rocket-launchers and terrifying residents of Bouake, while demanding bonuses, better pay and housing.

The protests then spread to other cities, including the economic capital Abidjan.

The mutiny saw President Alassane Ouattara order major changes in the top security ranks, the armed forces' chief of staff, the senior commander of the national gendarmerie and the director-general of the police.

"The troops have agreed to return to their barracks, and for this reason gunfire has halted in Bouake," a local official said. He said the mutineers had managed to obtain a bonus of about $8,000.

While an initial deal had been reached almost a week ago, talks on implementing the agreement only began on Friday and tensions were high with mutinying troops taking up positions on the roads into Bouake and firing into the air.

READ MORE: Soldiers launch mutinies in three Ivory Coast cities

Regular gunfire was heard throughout the day, including at Akouedo, the biggest barracks in Abidjan and at Odienne in the northwest and Bondoukou in the east.

One source said the soldiers had originally been demanding a raise of about $16,000 each, a significant amount given that many Ivorians earn about $160 a month.

It remains to be seen how the government will finance its promise of the agreed $8,000 bonus.

The Ivorian army, which consists of about 22,000 soldiers, includes many former rebels who were integrated into the armed forces after years of conflict.

"The president is honouring the promises that he made towards former rebels who fought alongside him back in 2010's civil war," Kamissa Camara, a senior programme officer for West and Central Africa at the National Endowment for Democracy, told Al Jazeera.

"Not only that, but he is also honouring the promises made by the former leaderships towards the army.

"So they have a big task ahead of them to make sure that the situation remains stable," Camara said, adding that the mutiny has tainted the political situation of the country.

READ MORE: Alassane Ouattara dismisses security chiefs as PM quits

Bouake, which is home to 1.5 million people, was the cradle of a rebellion which erupted in 2002 in a failed attempt to oust then-president Laurent Gbagbo.

The revolt sliced the former French colony into the rebel-held north and the government-controlled south and triggered years of unrest.

Twelve years later, a similar dispute over pay by rebels-turned-soldiers erupted in Bouake which spread to Abidjan and briefly brought the country to a standstill.

The government then agreed to a deal that provided amnesty for the mutineers and a financial settlement.