South Sudanese soldiers celebrate outside the United Nations mission in Malakal after recapturing the town from rebels.andnbsp;Agence France-Presse/Getty Images

KAMPALA—South Sudan troops have recaptured Malakal, the capital of the state that is home to the country's only functioning oil fields, ending more than a month of rebel occupation amid faltering regional efforts to broker a truce in the nearly four-month-old conflict.

Government troops seized control of Malakal, located 400 miles north of the capital Juba, after a two-day gunbattle with rebels loyal to former vice president Riek Machar, military spokesman Col. Philip Aguer told The Wall Street Journal.

Malakal, the capital of Upper Nile state, has changed hands several times since the conflict between rebel fighters and government troops erupted in mid-December, raising concerns over the safety of the vast oil fields in the beleaguered nation.

"Our forces have finally taken full control of Malakal, the rebels are in disarray," Col. Aguer said, adding that rebels had virtually "destroyed and looted everything" during their monthlong occupation.

Sudan's Tumultuous History

Review events on the fragmented political situation of South Sudan, which itself broke away from Sudan in 2011 and has repeatedly clashed with its neighbor over oil production and exports.

Fighting broke out on Tuesday after rebels tried to extend their positions outside the town, in an attempt to advance toward the oil fields that lie more than 100 miles north of Malakal.

Col. Aguer also said government forces had beaten off a rebel attack on Wednesday, around 15 miles west of the Adar oil field. A rebel spokesman couldn't immediately be reached for comment on the latest developments.

Oil companies have evacuated hundreds of foreign workersandnbsp;as the fighting has spread. Crude shipments from South Sudan have dropped by up to 30% to 165,000 barrels a day since December, according to government data.

The United Nations mission in South Sudan said Wednesday that its base in Malakal had been caught in the crossfire of the latest fighting, threatening the safety of thousands of refugees under its protection.

The recapture of Malakal comes the same day asandnbsp;warring parties are due to resume peace talksandnbsp;in Ethiopia, in the latest attempt to enforce a tattered cease-fire deal that was signed in January.

Both sides remain at odds in the talks over several issues, such as the fate of political prisoners and the involvement of regional armies in the conflict.

Mediators from the East African regional trade bloc, the Intergovernmental Authority on Development, have proposed deploying a stabilization force to monitor the cease-fire. But the rebels oppose such a deployment and have threatened to pull out of the talks over the matter.

The conflict has splintered South Sudan along ethnic lines, pitting President Salva Kiir's Dinka community against Mr. Machar's ethnic Neurs.

Nearly 1 million people have been displaced and more than 10,000 people are believed to have been killed since the conflict began, aid agencies say.

Write toandnbsp;Nicholas Bariyo atandnbsp;[email protected]