Pakistan and Afghanistan have stepped back from a near-rupture in relations following the murder of an Afghan peace envoy, officials said on Wednesday after several days of talks between the two countries.

Leaders of the two countries, accompanied by their army and intelligence chiefs, met at a regional conference hosted by Turkey for the first time since the assassination in September of peace envoy and former president Burhanuddin Rabbani.

We gained more than we hoped for. We broke the ice, a Turkish official said of his country's efforts to help repair a relationship essential to ending the war in Afghanistan.

We all know the story here - it's difficult, a senior western diplomat said. They know the bottom line is that they do actually need each other.

Afghanistan had earlier cancelled talks with Pakistan after Rabbani's killing in Kabul by a suicide bomber posing as a Taliban peace emissary who Afghanistan said was sent from the Pakistani city of Quetta.

The assassination also prompted Afghan President Hamid Karzai to say there was no point in talking to the Taliban and that Afghanistan should instead deal directly with Pakistan, which it accuses of supporting and sheltering the insurgents.

Afghan and Pakistani officials, however, both indicated a willingness to try again to explore peace talks with insurgents - though they differ on how these should be approached.

Kabul has in the past accused Pakistan of interfering in the

peace process and of backing the Afghan Taliban - including those in the so-called Quetta shura and the Haqqani network - to extend its own influence in Afghanistan and counter rival India.

In our discussions we ask Pakistan again and again to allow the Quetta shura to come and sit with Afghanistan at the negotiating table to find, to explore a peaceful solution, Karzai's National Security Adviser Rangeen Dadfar Spanta said.

We are ready to talk to everybody, every Afghan citizen if he or she is ready to talk for peace and stability in Afghanistan, he told Reuters.

A day after a trilateral summit hosted by Turkey, Afghanistan and Pakistan along with other countries in the region also signed up to a declaration on Wednesday reaffirming support for an Afghan-led process of reconciliation.

We have to make damage control (after Rabbani's killing), another senior western diplomat said. We have to make clear we don't delete the file of reconciliation.

NO ROAD MAP

Pakistan, increasingly worried about the war in Afghanistan spilling over into its own territory, has long called for talks with Taliban insurgents.

Such talks have been endorsed by the United States - provided insurgents are willing to sever ties with al Qaeda, renounce violence and respect the Afghan constitution.

Rabbani's assassination had torpedoed a process seen as helping to pave the way for the United States and its allies to pull out most combat troops from Afghanistan by 2014.

Both Pakistan and Afghanistan are seen as needing to work together to bring the Taliban to the negotiating table.

Pakistani Interior Minister Rehman Malik - who denied his country supported the Taliban - told Reuters Pakistan was ready to help in any Afghan-led peace process.

We want a safe, stable Afghanistan. We want to be good neighbours, he said. But it was up to Karzai to set objectives on what was expected from the peace process, he added. There is no clear road map.

Pakistan has also suggested a cease-fire could help create the right climate for talks to succeed - whereas the United States has said it will fight and talk at the same time.

During their meetings in Istanbul, Afghanistan and Pakistan agreed to set up a joint mechanism to investigate Rabbani's assassination.

Pakistan's Malik, however, said that Islamabad had turned down a suggestion for a joint investigation. They demanded a joint commission. A joint commission is not allowed under our law.

But he promised Pakistan would investigate any leads and details given by Afghanistan. We will do everything possible to help Afghanistan to bring the culprits to justice.

Afghan and Pakistani officials gave different views on the identity of Rabbani's killer.

A senior Afghan official, speaking on background, told Reuters documents found on the body of the suicide bomber showed he was a Pakistani national.

Malik said no Pakistani was involved but noted that many Afghan refugees had been living in Pakistan for decades and had in the past often obtained false identity papers.

With the thaw in relations still tentative, Afghanistan has said it will judge Pakistan's willingness to help bring peace to the country on the basis of its actions rather than words.

We will establish our relationship with Pakistan on the basis of mutual trust and cooperation, Spanta said.

After the assassination of President Rabbani this relation and this trust basis was destroyed. The discussion between us, Turkey and Pakistan was an effort to bring some movement in bilateral relations between the two countries but I'm not sure that we had success.

But Pakistan, the senior Afghan official said, had promised during their Istanbul talks - which included an unscheduled dinner on Tuesday between the two presidents along with their military and intelligence officials - to cooperate.

(Additional reporting by Tulay Karadeniz; Editing by Tim Pearce)