President Bush's national security adviser waded into a tense dispute between two key allies Monday as he urged Afghanistan and Pakistan to work more closely together in the hunt for al Qaeda and Taliban fugitives believed hiding along the border between the neighboring countries.

Wrapping up a two-day visit to Afghanistan before heading to Pakistan, Stephen J. Hadley said the two nations and the United States had "made progress" in tracking down guerrillas, but he added, "we all need to do more."

[The visit came on a day when an American soldier and a Marine were killed in separate incidents, news services reported Tuesday. Another soldier was injured.]

Afghan officials used Hadley's stop to press their case that Pakistan has provided refuge for Islamic extremists who cross the border freely, including members of the revived Taliban militia that was driven from power by the U.S.-led invasion in 2001. Pakistani officials, in turn, have defended their efforts against the radicals and pointed the finger back at Kabul.

"There are people in the border areas of Pakistan that threaten my country, threaten Pakistan and threaten Afghanistan," Hadley told reporters at the heavily guarded U.S. Embassy. "All three of us are threatened and all three of us have to cooperate in the solution."

In a later interview aboard his Air Force jet as he flew to Islamabad, the Pakistani capital, Hadley suggested that Pakistan should coordinate military operations with Afghan and U.S. forces to squeeze guerrillas from both sides of the border at the same time.

"In Pakistan, we need to be doing what we do in Afghanistan, having forces up on the border," he said. "What we and the Pakistanis and Afghans can do is share intelligence" and "coordinate our activities on the border." Ideally, he added, Pakistani forces would drive guerrillas west "so they flee into our arms and the Afghans'."

But Hadley strove not to take sides in the quarrel between the two nations, which have a long and complicated relationship. After a 2 1/2-hour dinner with Afghan President Hamid Karzai Sunday night, Hadley expressed understanding of the Afghan argument that Pakistan is the source of its problems with guerrilla attacks but did not fully endorse it.

"Clearly there is an element of that," he said in the interview. "But it is also clear there is an element that is indigenous to Afghanistan."

Gen. Pervez Musharraf, the Pakistani president, has countered Afghan complaints by suggesting that a fence be built along the border.

Hadley, who took over as Bush's principal foreign policy aide after Condoleezza Rice became secretary of state in January, spent much of Monday in the dusty provincial town of Gardez, about 80 miles south of the capital, where he visited a new army base and a police training site.

After arriving in Islamabad, he had dinner with his Pakistani counterpart, Tariq Aziz. Hadley planned to meet with Musharraf on Tuesday before traveling to the border town of Peshawar to review efforts to roust insurgents from the lawless tribal areas.

During his Kabul news conference, Hadley defended the ongoing U.S. military activity days after Karzai publicly called on the U.S. military to turn away from controversial air operations and house searches.