The US will not repeat its error of neglecting Afghanistan and allowing extremists to take over, Defence Secretary Robert Gates says.
Gen Musharraf is a 'strong ally', Mr Gates says
He was speaking after talks in neighbouring Pakistan with President Pervez Musharraf.
Nato and Afghan forces are preparing for a Taleban offensive this spring.
On Sunday the governor of Afghanistan's southern Helmand province said up to 700 insurgents had crossed from Pakistan to fight British forces.
Afghanistan and Pakistan share a 1,400-mile (2,250km) mountainous border.
Taleban and al-Qaeda fighters are thought to be operating on both sides of the border which is extremely difficult to patrol.
Mr Gates was on his first trip to Pakistan since becoming US Defence Secretary.
Militants say they can move around the border area with impunity
"My first visits to Pakistan were over 20 years ago and were in connection with our mutual effort to help the Afghans drive the Soviet troops from their territory," he told journalists.
"After the Soviets left, the United States made a mistake. We neglected Afghanistan and extremism took control of that country.
"We won't make that mistake again. We are here for the long haul."
Mr Gates said that in his talks with the Pakistan government he had discussed ways that Pakistan could work with US commanders in Afghanistan to pressure insurgents on both sides of the border.
He said the allies had a chance to deal a strategic setback to the Taleban and described Pakistan as a very strong ally.
The BBC's Barbara Plett in Islamabad says that Mr Gates did not repeat criticism expressed by other US and Nato officials that Islamabad is not going after Taleban fighters who take refuge on its soil.
President Musharraf has admitted there are weak points in policing the border and that the Taleban do get support from within Pakistan.
But he has strongly denied any official backing for the Taleban.
He has also refused to take sole responsibility for the border, saying that border security must be a joint effort with forces on the Afghan side.
Our correspondent says that Western officials acknowledge President Musharraf's difficulties, but they are afraid that the Taleban are using Pakistan to prepare for a spring offensive. More high-level visits here are expected to Pakistan shortly.
Gen Musharraf's government has also come under fire for pacts with tribal militants in the North and South Waziristan areas. Critics say the deals give Taleban fighters based there freedom to go where they please.
The new Nato commander in Afghanistan, Gen Dan McNeill, says that 2,000 extra troops are needed to patrol the border with Pakistan.
There are currently around 33,000 troops from 37 nations in Afghanistan.