UK Prime Minister Tony Blair and Afghan President Hamid Karzai have said terrorists blamed for attacks in both countries must be defeated.
President Karzai is due to address a London mosque
The two men were speaking at a news conference after talks in London.
Mr Blair said London's bombers and others used Iraq and Afghanistan as an excuse. He again denied the invasion of Iraq had made Britain a target.
President Karzai said Afghanistan shared the UK's pain, and called for people to unite against terrorism.
He said Afghans shared the suffering of people in London following the suicide bombings which killed more than 50 people there on 7 July.
"We in Afghanistan can feel that pain perhaps better than any other country," he told reporters.
Afghanistan is facing an upsurge in violence, blamed on hardline Taleban fighters, which has claimed at least 600 lives this year.
Mr Karzai said the violence in Afghanistan and the UK was "not related to Islam". He said Muslims had been targeted in the attacks, and he condemned the recent assassinations of clerics in Afghanistan and bombings at mosques.
Mr Blair said it was important people did not give in to "the perverted and twisted logic" used by those who carried out the attacks.
"The Afghan people and the Iraqis are trying to establish a democracy. This same terrorism is trying to stop them."
President Karzai's visit is his third to the UK since he took over after the fall of the Taleban three-and-a-half years ago.
Through military and economic aid, Britain has played a central role in helping the country with its fragile efforts to recover from years of war and turmoil. The Afghan leader wants to ensure that help continues.
He and Mr Blair are due to sign a 10-year co-operation agreement.
In the light of the London attacks, President Karzai has decided to use his visit to speak out against extreme Islamic ideologies, a senior Afghan official told the BBC.
The views promoted by Osama Bin Laden will be a particular target. One place he plans to deliver this message is at a mosque in London.
Mr Karzai feels strongly about the issue, the official said, because of the suffering Afghanistan experienced as a result of becoming al-Qaeda's sanctuary until 2001.
Even though Bin Laden's network no longer has a firm base in Afghanistan, it is still seen as a threat to the country and is accused of helping to orchestrate the recent increase in violence.