Swiss President Hans-Rudolf Merz has apologised in Tripoli for the arrest in 2008 of one of the sons of the Libyan leader Moammar Gaddafi.
Two Swiss businessmen currently detained in Libya would be released "soon", according to a finance ministry statement.
"I express to the Libyan people my apologies for the unjust arrest of Libyan diplomats by Geneva police," Merz said in English at a joint news conference, according to AFP news agency.
Libyan Prime Minister al-Baghdadi Ali al-Mahmoudi said the two countries had agreed on a "normalisation" of their relationship – a decision that was confirmed by Merz – and they would set up a joint committee to examine what he called the "tragic incident" in Geneva.
Relations between the countries have been strained since July 2008 when Hannibal Gaddafi and his wife were arrested in Geneva, charged with assaulting two domestic employees.
The couple were freed after two days in custody on bail of SFr500,000 ($470,000) and the charges were later dropped, but Libya responded by suspending oil deliveries to Switzerland, withdrawing assets worth an estimated $5 billion (SFr5.3 billion) from Swiss banks, ending bilateral cooperation programmes and placing restrictions on Swiss companies.
In its statement on Thursday, the finance ministry said both countries would set up an independent court to look into the circumstances surrounding the arrest, and that Switzerland was "prepared to apologise for the improper and unnecessary arrest of Hannibal Gaddafi and his family by the Geneva police".
Merz told a journalist from AFP that the Libyans had promised him that the two Swiss hostages would be released before September 1.
"Today I have fulfilled my mission and achieved my goals of wiping the slate clean of last year's incident and opening the Libyan market [to Swiss firms]," he said, before returning to Bern on Thursday evening.
"It is a satisfying outcome for me."
Geneva's prosecutor dropped the case in September last year following the withdrawal by the plaintiffs of their formal complaint after they reached an undisclosed settlement with the Gaddafis.
Charles Poncet, a Geneva lawyer representing Libya, said on Thursday he was "very happy" that Bern and Tripoli had managed to overcome their differences. He added that a hearing on the civil suit due next month would be "suspended" as a first step and "certainly withdrawn".
Geneva authorities had rejected Libyan calls for an apology. "We have found that the rule of law was respected, that international conventions were not violated and in the final analysis, there was perhaps a problem of a lack of tact," the cantonal government president, David Hiler, said in January.
Foreign Minister Micheline Calmy-Rey last month said Switzerland intended to seek a meeting with the Libyan leader in order to help settle the dispute.
For Switzerland the dispute is "a matter of law, while for Libya it is a matter of honour", she said.
swissinfo.ch and agencies
Geneva lawyers dropped the case against Gaddafi and his wife in September 2008 after the two servants the Libyans had allegedly abused dropped their complaint.
An independent commission shed light on the arrest in a report released on December 14, 2008. It concluded that Geneva police had committed no illegal acts but criticised the force on several points, saying officers could have used more tact.
In April 2009, Hannibal Gaddafi filed a civil complaint against canton Geneva, arguing that the Vienna Convention on Diplomatic Relations had been breached.
According to the lawyer representing the Libyans, Charles Poncet, records of civil proceedings against the canton will be filed in a court of first instance in Geneva on September 24, 2009.
In 2007 and 2008, Libyan oil accounted for over 50% of Swiss crude-oil imports.
Switzerland imports annually about 4.5 million tons of crude oil processed in two refineries and more than 7 million tons of refined products from Europe.
In Switzerland, the oil company Tamoil owns more than 350 service stations and the refinery Collombey in canton Valais. Libya holds 35% of the group's shares.
Libya is seeking to expand its export markets. It is estimated that Libya still has large reserves of oil and gas. Libyan oil is light and low in sulphur. Refining this gives excellent yields.
If Libya were to stop delivering oil to Switzerland, alternatives exist.
The international oil market is characterised by excess supply.
Over the past 30 years, the oil-producing countries have declared no oil embargoes.
However, consumer countries have imposed embargoes on imports from Libya, Iran, Iraq and Sudan.
Source: Nicolas Sarkis, director of the Arab Center for Petroleum Studies