Fighters from a militant Islamic group in Afghanistan, allied to the Taliban, have told the BBC they are considering joining forces with Islamic State (IS).
Their commander also said they would still fight the Afghan government, even after Nato forces left in 2014.
Commander Mirwais said that if IS, which he called by its Arabic acronym Daish, proved a true Islamic caliphate, they would link up with it.
The news comes amid an ongoing row over Afghanistan's presidential poll.
The June election remains disputed, with no declared winner, while an audit of votes is taking place.
"We know Daish and we have links with some Daish members. We are waiting to see if they meet the requirements for an Islamic caliphate," Commander Mirwais said.
"If we find they do, we are sure that our leadership will announce their allegiance to them. They are great mujahideen. We pray for them, and if we don't see a problem in the way they operate, we will join them."
The threat is a disturbing one. If any group does link up with IS, it would add an entirely new dimension to the struggle.
Across Afghanistan, there are currently 14 different front lines where the Taliban are fighting government forces.
One of them is around Pul-e-Khumri, the capital of Baghlan province in northern Afghanistan. It is less than 200km (120 miles) from Kabul, but it takes seven hours to drive there, across the mountains and through the Salang Pass.
The roads are often atrocious thanks to the web of local corruption, despite the huge amounts of Western money that have been lavished on them.
Through an intermediary, we had made contact with Commander Mirwais, whose group is fighting on the outskirts of Pul-e-Khumri.
Commander Mirwais has moved from group to group in the past, but now he belongs to Hezb-e-Islami, a group with a good deal of blood on its hands.
Over the years, Hezb-e-Islami has become famous for its ferocity, which has sometimes alienated even the Taliban themselves.
Among Western journalists, the group has had a bad reputation ever since the 1980s, when it invited a freelance cameraman working for the BBC to join one of its operations, then killed him during the night in order to sell his equipment.
Now, though, a reliable intermediary told us that Commander Mirwais would meet us and would guarantee our safety. We decided that we could trust these assurances - and it turned out that we were right.
For a front-line town, Pul-e-Khumri is prosperous and reasonably secure. Local people can hear the shooting at night time, and they know that the Taliban are present on three sides of them.
But the shops are full of goods, the streets are thronged with people, and the tea houses and kebab shops are doing good business.
We established ourselves in a small upstairs hotel in one of the main streets. It was uncomfortable and not overly clean, but it was run by a relative of our driver, which meant we were safe there.
In the end our Afghan cameraman had to go and see Commander Mirwais on his own.
At the appointed spot on a side road off the main northbound road out of Pul-e-Khumri, the commander emerged from the darkness, accompanied by a group of heavily armed bodyguards.
He turned out to be a rational figure, frank about his ideas and aims. But they were uncomfortable to Western ears.
"Our struggle was mainly against the Americans, and thank God they were forced to run away. But we will continue to fight until we establish an Islamic state," he said.
"Our operations are mostly guerrilla-style these days. The Kabul government is very weak now, like the Najibullah government after the Soviet withdrawal in 1989. We concentrate on explosions and targeted killings and ambushes.
"The government has no control beyond the tarmac roads. They can't go into the villages without massive force."
There was no suggestion from him, therefore, that once the Western troops have withdrawn, the Taliban and their allies would come to an agreement with the government in Kabul. Nothing short of an Islamic state run along Sharia lines will satisfy them, it seems.
A leading politician and intelligence expert in Kabul, Amrullah Saleh, dismisses the idea that the Taliban and their extremist allies could take power in Afghanistan. He maintains that politics and society there have changed too greatly for that to be possible.
Yet there is no doubt that extreme Islamist fighters do present a serious challenge to the Kabul government. Especially if they link up with the ultra-Islamists of IS in Iraq and Syria.
Afghanistan, surrounded by its mountains and deserts, has always been deeply cut off from the outside world. Now, for the first time, its insurgents are considering making common cause with groups far from their borders.
Correction 4 September: The headline of this article was revised to reflect the fact that in his interview Commander Mirwais was speaking for himself and his group of fighters, and not on behalf of Hezb-e-Islami, whose official position is not to have any ties with ISIS.