Fredy Builes / Reuters People celebrate the signing of a historic ceasefire deal between the Colombian government and FARC rebels at Botero square in Medellin, Colombia, June 23, 2016.

HAVANA, Aug 24 - Colombia’s government and leftist FARC rebels unveiled a final peace deal on Wednesday to end a 50-year-old guerrilla war, one of the world’s longest conflicts which took the resource-rich country to the brink of being a failed state.

The two sides said they had reached an agreement to end the conflict and build a stable peace, in a joint statement read out by representatives of Cuba and Norway, who are mediators in the talks.

The historic agreement foresees the demobilization of the Revolutionary Armed Forces of Colombia (FARC), whose cocaine-funded rebels fought the government in a war that killed at least 220,000 people. Tens of thousands disappeared and millions fled their homes because of the violence.

The deal, opposed by two former Colombian presidents, still needs to be voted on in a referendum and signed.

U.S. President Barack Obama spoke by phone with Colombian President Juan Manuel Santos on Wednesday to congratulate him on finalizing details of a peace agreement to end the country’s 50-year-old guerrilla war with FARC rebels, the White House said.

“The president recognized this historic day as a critical juncture in what will be a long process to fully implement a just and lasting peace agreement that can advance security and prosperity for the Colombian people,” the White House said in a statement.

Earlier on Wednesday, Colombia’s President Juan Manuel Santos said a big announcement was very close.

“May this country that you are imagining, that you are painting, become reality,” he said at the Bogota launch of a children’s art competition called “Depict a Colombia in Peace.”

“A country where children can grow without fear and with hope for the future,” he added.

The FARC said the countdown had begun to a final deal.

“I want to share with you from here in Havana the great satisfaction we feel to have reached this point,” said Rodrigo Londono, or Timochenko, the top leader of Marxist-inspired guerrillas.

FARC negotiator Pastor Alape tweeted overnight that “the days now are hours” until peace starts to take shape.

Most opinion polls suggest Colombians will back it. Still, Santos, who has staked his legacy on peace, will have to fight hard for a “yes” given fierce opposition from powerful sectors of the country who think the only solution is to crush the FARC militarily.

“A positive vote once seemed like a slam dunk,” said Tom Long, International Relations lecturer at Reading University.

“But opposition from former presidents (Andres) Pastrana and (Alvaro) Uribe will force Santos to campaign hard for the accord.”

A previous round of talks, under Pastrana between 1999 and 2002, collapsed after the guerrillas hijacked an airplane.

ADALBERTO ROQUE via Getty Images Members of the Colombian government's and FARC leftist guerrilla's delegations and guarantors for peace talks attend a press conference at the Convention Palace in Havana, on August 12, 2016.

BOON FOR BUSINESS

An agreement with FARC does not guarantee an end to violence that began as a peasant revolt. Talks between the smaller, leftist National Liberation Army and the government recently stalled, while gangs born out of right-wing paramilitary groups are reported to have taken over some of their drug trafficking routes.

But an agreement is a prerequisite for peace. A ceasefire has already sent violence to its lowest level in decades.

The improved security should boost investment and tourism and could open up development in rural regions of the emerging markets darling, analysts say, estimating a 0.3 percent to 1 percent increase in economic growth.

“If you have an improvement in overall security, foreign and national investment increases,” said Sabine Kurtenbach at the Hamburg-based GIGA research institute.

Key to securing a sustainable peace is that the extra growth benefits Colombia’s poorer, rural areas, analysts say.

The FARC was born, like many other Marxist-inspired peasant insurgencies across Latin America in the 1960s, out of frustration with deep socio-economic equalities.

Funded by cocaine and kidnappings for ransom, it grew to a 17,000 strong force operating across vast swaths of Colombia.

While other Latin American insurgencies had been crushed by right-wing governments or convinced to join conventional politics by the 1990s, the FARC was still going strong.

This only started to change when Uribe in 2002 launched a U.S.-backed counterinsurgency campaign that killed many FARC leaders and reduced its ranks to an estimated 7,000 fighters.

Uribe says the government is giving in to “terrorism” by negotiating with the FARC and granting it a degree of amnesty. His party, Colombia’s main opposition group, announced earlier this month it would back a “no” vote in the plebiscite.

Under accords already struck in Cuba, perpetrators of the worst crimes will face “transitional justice” aimed more at finding out the truth than meting out harsh punishment.