ISLAMABAD, Pakistan — For two years, Afghan officials have said it publicly and American troops have bitterly complained about it privately.

A large group of foreign militants who they suspect are allied with al-Qaida — and possibly Osama bin Laden himself — appear to be safely hiding in Pakistan's tribal areas and mounting cross-border attacks on American forces in Afghanistan. Pakistani forces at the border have apparently done little to stop them.

"If they'd cut the restraints," said one American soldier on patrol near the border last week, referring to their orders to stay on the Afghan side, "we'd go into Pakistan and kill them."

Developments in recent days indicate that Pakistan is finally willing to press its troops on the border to go after the foreigners, after two assassination attempts on President Pervez Musharraf by Islamic militants. But critics also point out that it could have happened a lot sooner.

The discovery of hundreds of foreign militants in South Waziristan, the focus of the current operation, also suggests that if there is a Qaida stronghold where bin Laden is hiding, it may be there.

But no concrete evidence has emerged to confirm Pakistani officials' suggestions that Ayman al-Zawahiri, al-Qaida's No. 2 leader, is trapped with the militants.

It also appears that Pakistani troops sent to the fiercely independent tribal areas more than two years ago failed to find militants who might have been living on their doorstep. Pakistani officials say the current battle involves 400 to 500 militants who gathered in villages only 10 miles from a large military base in the town of Wana without Pakistani forces' having realized it.

"Yes, we must confess they were surprised," a Pakistani military spokesman, Maj. Gen. Shaukat Sultan, said at a news conference on Monday, referring to the members of the raiding party that finally discovered the militants. "They had underestimated the strength of the miscreants there."

Afghan and some American officials contend that Pakistani forces have simply not tried to find the militants, or in some cases overtly aided them.

Zalmay Khalilzad, the American ambassador to Afghanistan, said in an interview with The Associated Press on Sunday that two Taliban commanders believed to be orchestrating attacks in southern Afghanistan were operating from Pakistan.

"We know several key Taliban figures are there," he said, "and there is some sense that some of the remaining al-Qaida leaders are in the border area on the other side."

Pakistani officials say that no one, including American officials, suspected that there were so many militants in South Waziristan. "They knew and we knew there were foreign elements," said a senior Pakistani official. "But nobody knew the number or the strength."