Colombia’s government and the Farc rebels signed a historic ceasefire deal in Havana on Thursday, bringing them tantalisingly close to ending the last major leftist insurgency in Latin America after more than five decades of war.

The accord, which caps three years of talks, paves the way for a final peace deal to end a conflict born in the 1960s out of frustration with deep socio-economic inequalities and that outlived other major uprisings in the Americas.

Mediating countries said Colombia and the Farc had agreed to lay down arms within 180 days of a final peace deal.

Colombian president Juan Manuel Santos and the head of the country’s leftist

Farc rebels have agreed on a ceasefire and rebel disarmament deal that moves the country to the brink of ending a 52-year war that has left more than 220,000 people dead.

At a ceremony in Havana, Mr Santos and Farc commander Rodrigo Londono, better known as Timochenko, listened to the reading of a deal laying out how 7,000 rebel fighters will demobilise and hand over their weapons once a peace accord is implemented.

In attendance were UN secretary-general Ban Ki-moon, a special US envoy and the presidents of Cuba, Chile, Venezuela and other Latin American countries.

A 15-year, US-backed military offensive thinned rebel ranks and forced Farc’s ageing leaders to the negotiating table in 2012.

In Mr Santos, a US-educated economist and scion of one of Colombia’s richest families, the rebels found a trusted partner who hailed from the conservative elite but was not bound by its prejudices.

Momentum had been building toward a breakthrough after Mr Santos said this week that he hoped to deliver a peace accord in time to mark Colombia’s declaration of independence from Spain on July 20th.

But the latest agreement went further than expected. In addition to a framework for the ceasefire, both sides said on Wednesday they agreed on a demobilisation plan that will see guerrillas concentrate in rural areas and hand over weapons that had long been the vaunted symbols of their movement’s origins as a self-defence force of peasant farmers attacked by the oligarchy-controlled state.

Negotiators in January agreed that the United Nations would be responsible for monitoring adherence to the eventual ceasefire and resolving disputes emerging from the demobilisation.

With the latest advance, only a few minor items remain to be worked out for a peace accord.

The biggest is how the final deal will be ratified and given legal armour so it will not unravel should a more conservative government succeed Mr Santos, who leaves office in 2018.

Mr Santos has also promised to let Colombians vote on accepting the final accord in a national referendum, and his government is not taking acceptance for granted.

A peace deal will not make Colombia safer overnight. The proliferation of cocaine has fuelled the conflict longer than any other in Latin America and will remain a powerful magnet for criminal gangs operating in Colombia’s remote valleys and lawless jungles.

Colombia is the largest supplier of cocaine to the US and only a small fraction of the country’s 12,000-plus homicides last year had anything to do with the conflict.

There is also the risk that the country’s second rebel movement, the much-smaller but more recalcitrant National Liberation Army, could fill the void left by the Farc.

That rebel group agreed to negotiations with the government earlier this year but those talks have yet to start because of Mr Santos’s insistence that it renounce kidnapping.

But if the Farc honour their commitments and the fighters are successfully integrated back into society, the government could begin shifting resources away from the battlefield and towards attacking other forms of crime and poverty and inequality.

Former president Alvaro Uribe, who spearheaded the military offensive against the Farc last decade, refused to comment on Wednesday’s announcement, saying he was waiting more details. Others could not hold back their excitement.

Leftist Senator Ivan Cepeda borrowed a phrase from Colombia’s beloved Nobel Prize-winning novelist, Gabriel Garcia Marquez, to compare the prospect of peace to a “second chance on earth”.

“It’s time to rid ourselves of hatred, lies and fears and build reconciliation among all our compatriots,” Mr Cepeda, one of the government’s most-trusted conduits to the Farc, said on Twitter. “Peace defeats death.”

Agencies