FOR a moment last week it seemed as if Pakistan was on the cusp of falling under the control of the Taliban. On Thursday their forces moved from the Swat valley to the north of the capital, Islamabad, and began occupying key points in the province of Buner. Government offices were seized and road blocks established in a show of strength which was made more remarkable by the fact that the fighters were within 60 miles of the capital.

"What law stops us going there?" asked Taliban commander Muslim Khan. "Our people will go there and stay as long as they want."

In response, President Asif Ali Zardari sent paramilitary forces into the province and by yesterday most of the Taliban forces had withdrawn from the occupied areas of Buner. It could have been sold to the rest of the world as a victory for the authorities and a step backwards for the insurgents' commander, Maulana Fazlullah, but the harsh reality of life in this unforgiving part of the world is that the Taliban have shown once again how close they are to controlling events in Pakistan. They decided when to move into Buner and when to return to their holdings in Swat, and demonstrated that they can easily do it again.

So alarmed was the US State Department by Fazlullah's audacious move into Buner that Secretary of State Hillary Clinton issued an immediate warning to Zardari that he had "no choice" but to confront the Taliban, which "now poses a mortal threat to the security and safety of our country and the world". The rebuke was repeated on Friday when Admiral Mike Mullen, chair of the US joint chiefs of staff, warned that Pakistan was reaching a "tipping point" and "events continue to move in the wrong direction".

This was not alarmist talk but the worried reaction of diplomatic realists who fear that the Taliban could easily gain a foothold in northern Pakistan from which they can dictate events in Afghanistan and threaten the rest of the sub-continent.

"We're not saying that Pakistan will fall to the Taliban, even though it's clear that large swathes of the country are under its control," said a US diplomatic source. "But we do feel that the Pakistani authorities are losing their grip and are in danger of appeasing the Taliban, who only view compromise as a sign of weakness."

The stark warnings were given a new edge when it emerged that the Taliban fighters had only agreed to a partial retreat into the nearby foothills of the Karakoram Mountains while Fazlullah attempts to cut a local deal in Buner permitting the imposition of sharia law. Similar in form to an agreement brokered in Swat 18 months ago to end a long-running confrontation, this will allow the Taliban to run the district administration and law courts and to introduce a strict interpretation of sharia law. In Swat men have been forced to grow beards, girls above the age of seven have to wear the burqa and schools have been blown up to put a stop to any western-style education. All this has attracted strong condemnation by Amnesty International, which regards Taliban-style government as an abnegation of human rights.

"The Pakistani government is fiddling as the North-West Frontier Province burns," said Sam Zarifi, the charity's Asia-Pacific director. "The Taliban in Buner are establishing themselves as the ruling authority instead of the Pakistani government, just as we've seen in several other areas they have taken over. The people of Buner are now at their mercy, particularly women and girls, whose rights the Taliban systematically deny."

The Taliban operation in Buner also sends a wake-up call to President Barack Obama, who has staked US interests in the region on creating an inclusive "Af-Pak" policy. Broadly speaking, this entails tying together Afghanistan and Pakistan to deal with regional problems and to admit that the Taliban have to be defeated in both countries if there is to be any progress. When the new plan was announced a fortnight ago, most strategists in Washington believed that the main battleground would be the tribal territories along the border between Afghanistan and Pakistan, but now the conflict seems to have come closer to Islamabad.

Speaking to US marines deployed to Afghanistan last Friday, defence secretary Robert Gates warned that they were about to meet an "existential threat" which had to be confronted and defeated before it got out of hand.

"It is important they not only recognise it, but take the appropriate actions to deal with it," he said. "The stability and the longevity of democratic government in Pakistan is central to the efforts of the coalition in Afghanistan. And it is also central to our future partnership with the government in Islamabad."

In addition to addressing the Afghanistan-bound marines at their base in North Carolina, Gates was also reinforcing the message to Zardari that Washington wants him to get to grips with the threat posed by the Taliban. The US is getting tired of the succession of local deals which allow regional governors and army commanders to arrange truces in return for the imposition of sharia law. All too often the agreements are only honoured in the breach and after a short time Taliban fighters re-appear carrying weapons and intimidating the local population.

If this continues, US commanders will lose patience and start taking the war to the Taliban, even if that means entering Pakistani territory. To date, these threats have been confined to the tribal territories where the US regularly deploys missile-armed drones to attack suspected targets, but there could be a sharp escalation. If Zardari continues to be seen to be doing nothing, analysts such as Ryan Clarke, Associate Research Fellow at the S Rajaratnam School of International Studies, Nanyang Technological University, claim that the US will be forced to increase its military activity across the region.

"It is becoming increasingly clear that Pakistan is not up to the job of extending its writ throughout all of its declared territory; confronting the Afghan Taliban and the al-Qaeda elements within their borders; ceasing the advance of the Pakistani Taliban; and, engaging in co-ordinated operations with Nato. Although a large-scale incursion into Pakistan's Tribal Regions is by no means a desirable option, recent actions by American forces demonstrate that Washington may come to view it as the only one."

However, as happened to the Pakistani leader's immediate predecessor, General Pervez Musharraf, Zardari is caught in a difficult position. Although he has signed up to Washington's demands to curb Islamic extremists and to take steps to improve the economy, recent opinion polls show that growing numbers of Pakistanis take exception to US interference in their country's affairs. Any talk of the US extending its operations into the tribal areas or even into Pakistan's North-West Frontier Province will only fuel that resentment.

"It must also be recognised that Pakistan has legitimate security interests in Afghanistan," points out Clarke, whose analysis was published by the Royal Institute for Defence Studies in London. "In autumn 2001 Pakistan lost a relatively friendly regime in Afghanistan and has seen that steadily replaced by former foes from the Northern Alliance and headed by the India-leaning Pashtun national Hamid Karzai."

During the last months of the Bush regime Islamabad found itself being sidelined by senior US commanders in Afghanistan and in Washington. Both the Pentagon and the CIA started scaling back intelligence-sharing with Pakistan's notoriously flaky Inter-Services Intelligence agency (ISI) and giving preference to the Indian security services. That was both a sign of the distrust in which the ISI is held by the CIA and an indication of the increasingly close links between Washington and New Delhi.

Any move of that kind would send alarm bells ringing in the high command of Pakistan's armed forces, because any rapprochement between India and the US will have ramifications in the disputed region of Kashmir. Although a ceasefire has held since 2003 there are regular breaches by Muslim fighters, many of whom belong to Lashkar i-Taiba whose doctrine embraces worldwide jihad. All too often these incursions are supported by the Pakistani forces on the border, or at best are simply ignored by them.

As Lashkar has ties with the Taliban - it was thought to be responsible for last year's bombing of the Taj Hotel in Mumbai - this only adds to the existing tensions between India and Pakistan. A recent poll in Pakistan shows that 80% of the army's senior commanders believe that India remains the primary threat and that operations against the Taliban in the north-west achieve little in return for causing unacceptable levels of casualties. No reliable figures have ever been made available but the International Red Cross estimates that 250,000 people have been made homeless along the frontier with Afghanistan as a result of military operations.

Much of this violence is blamed on US interventions and increases the perception that Pakistan is getting a poor deal in return for giving in to US demands. However, US diplomats are also aware that Obama's Af-Pak policy could come unstuck if it only succeeds in destabilising Pakistan, the very country which should be a key ally in the war against terrorism. On Friday the US State Department insisted that this was a problem which affected not only regional but global stability.

"We, the international community, have to help Pakistan meet these threats," said spokesman Robert A Wood. "But what's important is that Pakistan take the measures necessary to deal with the threat it faces. They need to take very decisive action to deal with these elements. These elements are a threat to not only Pakistan's internal security, but to its neighbours."