MOGADISHU (Reuters) - Somalia's prime minister said on Saturday he had secured a ceasefire between two warring regions in the Horn of Africa nation, two weeks after a peace deal collapsed leading to fighting that killed at least 29 people.

The Galmudug and Puntland semi-autonomous regions have a history of clashes and the latest round of fighting between their forces two weeks ago erupted after a dispute over buildings planned in Galkayo, a city that is divided between the two sides.

"Prime Minister (Omar) Sharmarke traveled to Galkayo and over (the) last week worked to negotiate an immediate ceasefire and an initiation of preliminary talks for a lasting peace agreement," a statement from his office said.

The statement said Sharmarke met Galmudug President Abdikarim Hussein Guled and Puntland President Abdiweli Mohamed Ali and witnessed a troop pull-back from the area where they clashed, and will have a four-kilometre buffer zone.

"What happened over the last month and weeks in Galkayo is very unfortunate. It is the responsibility of all here and absent to make sure we do not see a repeat,” Sharmarke said.

Somalia has been hit by conflict since the downfall of dictator Mohamed Siad Barre in early 1990s, and Islamist militant group al Shabaab has been one of the main causes of unrest in the last two decades.

(Reporting by Abdi Sheikh; Writing by George Obulutsa; Editing by Stephen Powell)