Image caption The UK says the aim is to help Pakistan and Afghanistan build closer co-operation

Afghan President Hamid Karzai and Pakistan's Asif Ali Zardari have said they will work towards a peace deal for Afghanistan within six months.

Speaking in Britain, after talks with Prime Minister David Cameron, they said they would "take all necessary measures" to achieve such a goal.

They backed the opening of an Afghan office in Doha and urged the Taliban to do the same for talks to take place.

The two men reaffirmed their aim to work towards a strategic partnership.

They said they hoped to sign an agreement strengthening ties on economic and security issues, including trade and border management, later in the year.

The talks - held at the UK prime minister's Chequers country retreat north of London - is the third round of discussions since Mr Cameron instigated the trilateral process last year.

Analysis It is worth noting that senior military and diplomatic chiefs are present at this meeting. They have not been at previous talks. On the Afghan side, everyone is admitting that Pakistan has taken positive steps. Senior officials point to the release of key Taliban leaders from prison, including former ministers - freeing them up to take part in a nascent peace process. But what they would really like to see is the release of Mullah Baradar - the Taliban's former second-in-command.

Foreign ministers, military leaders and intelligence chiefs attended the talks for the first time.

Nato troops are scheduled to withdraw from Afghanistan by the end of 2014.

Ahead of Nato's departure from Afghanistan, Pakistan does not want a repeat of the 1989 pullout by Soviet forces, which left Kabul in the hands of what it regarded as "unfriendly" forces. It fears this may extend Indian influence to its western border. Pakistanis want a secure Afghan border, an end to the Balochistan insurgency (which they blame on Afghanistan, India, the US and others) and co-ordinated action against anti-Pakistan guerrillas in both countries.

Overcoming mistrust

At a news conference with Mr Karzai and Mr Zardari, Mr Cameron said "an unprecedented level of co-operation" had been agreed between Afghanistan and Pakistan.

The discussions had centred on both the Afghan-led peace process and on strengthening co-operation between Afghanistan and Pakistan, he said.

The joint statement said all sides had agreed on the urgency of the Afghan peace process and "committed themselves to take all necessary measures to achieve the goal of a peace settlement over the next six months".

They called on the Taliban to open an office in Doha "to enter into dialogue" with the Afghan government, which has also set up a base in the Qatari city to conduct peace negotiations.

President Karzai and President Zardari also "re-affirmed their commitments" to signing a Strategic Partnership Agreement (SPA), to encourage closer ties.

Overcoming mistrust between Afghanistan and Pakistan remains a central issue, says BBC World Affairs correspondent Mike Wooldridge.

The Afghan government has made it clear that it views the recent release by Pakistan of a number of Taliban prisoners as positive, he says.

But it still wants the release of the former second-in-command of the Afghan Taliban, Mullah Baradar, in the hope that a senior figure like him could influence the Taliban to engage in talks with Kabul.

The first two rounds of the trilateral talks were held in Kabul and New York last year.