The Colombian government and left-wing Farc rebels have signed a historic agreement that formally brings an end to 52 years of civil war.

The rebel leader Timoleon Jimenez, known as Timochenko, apologised to “all the victims of the conflict” and was greeted by cheers and applause.

He said: “I would like to ask for forgiveness for all the pain that we have caused during this war.”

Guests dressed in white at the ceremony in Cartagena, to symbolise peace.

The UN Secretary-General, Ban Ki-Moon, and leaders of Latin American countries were among those present.

The last of the major Cold War conflicts killed 260,000 people and left six million internally displaced.

Who are the Farc?

President Santos: From hawk to dove

Timochenko, the guerrilla leader who talks peace

Inside the village where Farc rebels will lay down their arms

President Juan Manuel Santos said: “We will achieve any goal, overcome any hurdle and turn our nation into a country we’ve always dreamed of – a country in peace.”

Timochenko said the Farc, a group founded as the armed wing of the Communist Party in 1964, is leaving armed conflict behind and moving in to peaceful politics.

“No-one should doubt that we are moving into politics without arms,” he said.

“Let us all be prepared to disarm our hearts.”

The president and Timochenko used a pen made from a bullet to sign the deal.

The deal must pass a referendum on Sunday before it can pass into law. Polls indicate the majority of Colombians will vote for it, although there has been some opposition, led by two ex-presidents.

Under the deal, the Farc will be relaunched as a political party. The entire peace agreement will be put to Colombian voters in a popular vote on 2 October.

It comes after four years of talks in Havana, Cuba, between President Santos and Timochenko.

About 2,500 foreign and local dignitaries witnessed the signing ceremony in the walled, colonial city of Cartagena.

The president said the decision to use a bullet-pen was intended to illustrate Colombia’s transition from a country of bullets into a country of “education and future”.

Correspondents say President Santos has risked his political future on the success of the peace deal.

Dignitaries attending the ceremony include UN Secretary General Ban Ki-moon, US Secretary of State John Kerry and Cuban President Raul Castro.

“This step that your country is going to take is a giant step,” Mr Kerry said as he arrived in the country.

He praised the efforts of Mr Santos to secure the deal and and pledged $390m (£300m) to help implement it.

The US is not yet ready to remove the Farc from its list of terrorist organisations, he said, but is prepared to review that sanction once the peace agreement is up and running.

However, only hours before the signing, the EU announced it was removing the Farc from its list.

“This decision will allow us to support the post-conflict programme and will be of benefit to all Colombians,” EU foreign policy chief Federica Mogherini said on social media.

Correspondents say that although there is widespread hope that the deal may bring an end to the kidnappings and bloodshed that have blighted Colombia over five decades, it has also led to divisions in Latin America’s fourth-biggest economy.

Some are angry that it allows rebels to enter parliament without serving time in prison.

Farc rebels must now hand over weapons to the UN within 180 days.

The Farc’s 52-year fight

1964: Set up as armed wing of Communist Party

2002: At its height, it had an army of 20,000 fighters controlling up to a third of the country. Senator Ingrid Betancourt kidnapped and held for six years along with 14 other hostages

2008: The Farc suffers a series of defeats in its worst year

2012: Start of peace talks in Havana

2016: Definitive ceasefire