Pakistan retaliated by shutting down vital NATO supply routes into Afghanistan, used for sending in just under a third of the alliance's supplies.
The attack is the worst single incident of its kind since Pakistan uneasily allied itself with Washington in the days immediately following the September 11, 2001 attacks on U.S. targets.
Relations between the United States and Pakistan, its ally in the war on militancy, have been strained following the killing of al Qaeda leader Osama bin Laden by U.S. special forces in a raid on the Pakistani garrison town of Abbottabad in May, which Pakistan called a flagrant violation of sovereignty.
A spokesman for NATO-led troops in Afghanistan confirmed that NATO aircraft had been called in to support troops in the area and had probably killed some Pakistani soldiers.
"Close air support was called in, in the development of the tactical situation, and it is what highly likely caused the Pakistan casualties," said General Carsten Jacobson, spokesman for the International Security Assistance Force (ISAF).
He added that he could not confirm the number of casualties, but ISAF is investigating the "tragic development."
"We are aware that Pakistani soldiers perished. We don't know the size, the magnitude," he said.
The Pakistani government and military brimmed with fury.
"This is an attack on Pakistan's sovereignty," said Prime Minister Yusuf Raza Gilani. "We will not let any harm come to Pakistan's sovereignty and solidarity."
The Foreign Office said it would take up the matter "in the strongest terms" with NATO and the United States.
The powerful Chief of Army Staff, General Ashfaq Pervez Kayani, said in a statement issued by the Pakistani military that "all necessary steps be under taken for an effective response to this irresponsible act.
"A strong protest has been launched with NATO/ISAF in which it has been demanded that strong and urgent action be taken against those responsible for this aggression."
Two military officials said that up to 28 troops had been killed and 11 wounded in the attack on the outposts, about 2.5 km (1.5 miles) from the Afghan border. The Pakistani military said 24 troops were killed and 13 wounded.
EARLY MORNING ATTACK
It remains unclear what exactly happened, but the attack took place around 2 a.m. (2100 GMT) in the Baizai area of Mohmand, where Pakistani troops are fighting Taliban militants.
"Pakistani troops effectively responded immediately in self-defense to NATO/ISAF's aggression with all available weapons," the Pakistani military statement said.
The commander of NATO-led forces in Afghanistan, General John R. Allen, said he had offered his condolences to the family of any Pakistani soldiers who "may have been killed or injured."
The U.S. embassy in Islamabad also offered condolences.
About 40 Pakistani army troops were stationed at the outposts, military sources said. Two officers were reported among the dead.
"The latest attack by NATO forces on our post will have serious repercussions as they without any reasons attacked on our post and killed soldiers asleep," said a senior Pakistani military officer, requesting anonymity.
Reflecting the confusion of war in an ill-defined border area, an Afghan border police official, Edrees Momand, said joint Afghan-NATO troops near the outpost on Saturday morning had detained several militants.
"I am not aware of the casualties on the other side of the border but those we have detained aren't Afghan Taliban," he said, implying they may have been Pakistani or other foreign national Taliban operating in Afghanistan.
The Afghanistan-Pakistan border is often poorly marked, and Afghan and Pakistani maps have differences of several kilometers in some places, military officials have said.
However Pakistani military spokesman Major-General Athar Abbas said that NATO had been given maps of the area, with Pakistani military posts marked out.
"When the other side is saying there is a doubt about this, there is no doubt about it. These posts have been marked and handed over to the other side for marking on their maps and are clearly inside Pakistani territory."
The incident occurred a day after Allen met Kayani to discuss border control and enhanced cooperation.
"After the recent meetings between Pakistan and ISAF/NATO forces to build confidence and trust, these kind of attacks should not have taken place," a senior military source told Reuters.
BLOCKED SUPPLIES
NATO supply trucks and fuel tankers bound for Afghanistan were stopped at Jamrud town in the Khyber tribal region near the city of Peshawar hours after the raid, officials said.
"We have halted the supplies and some 40 tankers and trucks have been returned from the check post in Jamrud," Mutahir Zeb, a senior government official, told Reuters.
Another official said the supplies had been stopped for security reasons.
"There is possibility of attacks on NATO supplies passing through the volatile Khyber tribal region, therefore we sent them back toward Peshawar to remain safe," he said.
The border crossing at Chaman in Baluchistan was also closed, Frontier Corps officials said.
Pakistan is a vital land route for nearly half of NATO supplies shipped overland to its troops in Afghanistan, a NATO spokesman said. Land shipments only account for about two thirds of the alliance's cargo shipments into Afghanistan.
A similar incident on Sept 30, 2010, which killed two Pakistani troops, led to the closure of one of NATO's supply routes through Pakistan for 10 days.
NATO apologized for that incident, which it said happened when NATO gunships mistook warning shots by the Pakistani forces for a militant attack.
U.S.-Pakistan relations were already reeling from a tumultuous year that saw the bin Laden raid, the jailing of a CIA contractor, and U.S. accusations that Pakistan backed a militant attack on the U.S. embassy in Kabul.
The United States has long suspected Pakistan of continuing to secretly support Taliban militant groups to secure influence in Afghanistan after most NATO troops leave in 2014. Saturday's incident will give Pakistan the argument that NATO is now attacking it directly.
"I think we should go to the United Nations Security Council against this," said retired Brigadier Mahmood Shah, former chief of security in the tribal areas. "So far, Pakistan is being blamed for all that is happening in Afghanistan, and Pakistan's point of view has not been shown in the international media."
Other analysts, including Rustam Shah Mohmand, a former ambassador to Afghanistan, said Pakistan would protest and close the supply lines for some time, but that ultimately "things will get back to normal."
Paul Beaver, a British security analyst, said relations were so bad that this incident might have no noticeable impact.
"I'm not sure U.S.-Pakistan relations could sink much lower than they are now," he said.