His comments came after the Taliban overthrew the previous government and held a press conference declaring the country an "Islamic Emirate", rather than a democracy.
The prime minister "underlined" in a phone call with his Pakistani counterpart Imran Khan that any move to recognise a Taliban government must "happen on an international, not unilateral basis", a Downing Street spokesman said.
But he suggested there could be a way for the Taliban to win recognition from the international community.
"He said any legitimacy of any future Taliban government will be subject to them upholding internationally agreed standards on human rights and inclusivity," according to a Downing Street statement released following the call.
It went on: "The prime minister and prime minister Khan agreed their governments will keep in close contact in the coming days on the evolving situation."
Labour leader Sir Keir Starmer earlier said the Taliban must not be recognised as a legitmate government because "they've just swept in with force".
It appears the Taliban is keen to be accepted by countries around the world.
The group held a press conference declaring that nobody in Afghanistan should be "worried about our norms and principles", and that the rights of women would be respected within the "frameworks of Sharia" law.
He said: "Our women are Muslim, they will also be happy to be living within our framework of Sharia."
"The Islamic Emirate - after the freedom of this nation - is not going to revenge anybody, we do not have any grudges against anybody," he added.
"We have pardoned anyone, all those who have fought against us. We don't want to repeat any conflict, any war, again, and we want to do away with the factors for conflict.
"Therefore, the Islamic Emirate does not have any kind of hostility or animosity with anyone, animosities have come to an end, and we would like to live peacefully.
"We don't want any internal enemies and any external enemies."
Speaking to US President Joe Biden on Tuesday evening, Mr Johnson stressed the importance of preserving the progress made in Afghanistan over the past couple of decades.
A No 10 spokesperson said: “The Prime Minister stressed the importance of not losing the gains made in Afghanistan over the last 20 years, of protecting ourselves against any emerging threat from terrorism and of continuing to support the people of Afghanistan.”