Colombian President Juan Manuel Santos and the leader of the country's largest rebel group announced on Wednesday an important breakthrough in peace talks that sets the stage to end Latin America's longest-running armed conflict.

In a joint statement from Cuba, Santos and the Revolutionary Armed Forces of Colombia said they have overcome the last significant obstacle to a peace deal by settling on a formula to punish belligerents for human rights abuses committed during a half century of bloody, drug-fueled fighting.

"We are on different sides but today we advance in the same direction, in the most noble direction a society can take, which is toward peace," said Santos, minutes before a historic, cold-faced handshake with the military commander of the FARC guerrillas, known by his alias Timochenko.

Rebels that confess abuses to special peace tribunals, compensate victims and promise not to take up arms again will receive a maximum 8 years of labor under unspecified conditions but not prisons. War crimes committed by Colombia's military will also be judged by the tribunals and combatants caught lying will face penalties of up to 20 years in jail.

Santos flew earlier in the day to Havana, where talks with the rebel group have been going on for three years. Negotiators said the surprise advance came as rebels rushed to demonstrate progress ahead of a visit this week to Cuba by Pope Francis, who during his stay on the communist-led island warned the two sides that they didn't have the option of failing in their best chance at peace in decades.

Santos said the FARC vowed to demobilize within 60 days of a definitive agreement, which he said would be signed within six months.

Negotiators must still come up with a mechanism for rebels to demobilize, hand over their weapons and provide reparations to their victims. Santos has also promised he'll give Colombians the chance to voice their opinion in a referendum and any deal must also clear Congress.

U.S. Secretary of State John Kerry said he called Santos to congratulate him and his negotiating team.

"Peace is now ever closer for the Colombian people and millions of conflict victims," Kerry said in a statement.

As part of talks in Cuba, both sides had already agreed on plans for land reform, political participation for guerrillas who lay down their weapons and how to jointly combat drug trafficking. Further cementing expectations of a deal, the FARC declared a unilateral cease-fire in July, a move that ushered in most peaceful period in Colombia since 1975, according to CERAC, a Bogota think tank that monitors the conflict.

But amid the slow but steady progress, one issue had seemed almost insurmountable: How to compensate victims and punish FARC commanders for human rights abuses in light of international conventions Colombia has signed and almost unanimous public rejection of the rebels.

The FARC, whose troops have thinned to an estimated 6,400 from a peak of 21,000 in 2002, have long insisted they haven't committed any crimes and aren't abandoning the battlefield only to end up behind bars. They say that they would only consent to jail time if leaders of Colombia's military, which has a litany of war crimes to its name, and the nation's political elite are locked up as well.

"It's satisfying to us that this special jurisdiction for the peace has been designed for everyone involved in the conflict, combatants and non-combatants, and not just one of the parties," Timochenko, whose real names is Rodrigo Londono, said in a brief statement sitting alongside Santos and Cuban President Raul Castro, all three men in white shirts. "It opens the door to a full truth."

The breakthrough was hatched far from the klieg lights of Havana by a group of six lawyers in a 20-hour negotiating session last Thursday at the Bogota apartment of a former president of Colombia's constitutional court, negotiators told The Associated Press.

The marathon session wrapped up at 5:30 a.m. just three hours before the FARC's advisers were on a commercial flight to Havana to get the commanders' blessing, according to Douglass Cassel, a University of Notre Dame law professor who was one of the government's three representatives at the talks.

Cassel said the FARC worked overtime in the hopes of securing the deal ahead of Pope Francis' arrival Saturday to Cuba but in the end fell short of the goal. The sticking point he said was what would happen if the FARC lied to special tribunals and guarantees that the rebels wouldn't be extradited to the U.S., where they face charges for cocaine trafficking, if they honored their commitments.

"Without even being present physically in the room he was a very important presence," said Cassel of the pope.

Vatican spokesman Rev. Federico Lombardi credited the agreement to Francis' appeal.

"Maybe we can connect this good news of today with the appeal of the pope on Sunday. I think this is a positive sign," Lombardi said in a statement.

The government has gone to great lengths to insist that its framework for so-called transitional justice doesn't represent impunity for guerrilla crimes such as the kidnapping of civilians, forced recruitment of child soldiers and sexual violence. Only lesser crimes such as rebellion will be amnestied.

But even before details have become known, former President Alvaro Uribe lashed out at what he said was excessive lenience on the part of the government, foreshadowing the difficult road ahead to implement any final agreement. Human Rights Watch said it was difficult to imagine how the provisions for justice could survive a review from Colombia's constitutional court and the International Criminal Court if those who committed abuses don't spend a single day in prison.

"The government accepts that the criminals aren't going to jail," Uribe, whose military offensive last decade winnowed the FARC's ranks and pushed its leaders to the negotiating table, said at a meeting with supporters. "This is a bad example for society that will generate more violence."

Santos repeated Wednesday that he'll submit to a popular referendum any final agreement, which also must clear the country's congress.

Enrique Santiago, a Spanish lawyer who helped write the agreement on behalf of the FARC, told The Associated Press that the deal had the strongest safeguards against impunity of any peace deal to date.

"If the FARC don't want to step inside a jail they'll have to recognize their crimes," Santiago said