, are paying a deadly price in the war against the Taliban and Al Qaeda. America is fast losing the battle for hearts and minds, and unless the Pentagon comes up with a better strategy, the United States and its allies may well lose the war.

According to Human Rights Watch, at least 540 Afghan civilians died in fighting related to the conflict in the first seven months of this year. It says the Taliban were responsible for 367 of those deaths; 119 Afghans died in United States and NATO airstrikes, while 54 died in other American and NATO attacks.

The group’s numbers for American and NATO-caused civilian deaths were much higher last year — 434 deaths, including 321 from airstrikes — but the 2008 figures are still unacceptably high. And they do not count an airstrike last month in which Afghan officials charge that 95 people died. Washington disputes that number, and there needs to be a credible investigation.

Afghans once looked on American troops as their liberators, but far too many have come to see them as enemies. Add to that the corruption and incompetence of the government of Afghanistan’s American-backed president, Hamid Karzai, and we fear Afghans are being driven back into the hands of the repressive Taliban.

There are too few American and NATO troops in Afghanistan to wage this fight on the ground. So the war against an increasingly powerful Taliban is often fought from the sky. Bombs dropped in populated areas increase the chances of deadly mistakes. In 2007, under pressure from Mr. Karzai, NATO made changes in targeting tactics, including delaying attacks in areas where civilians might be harmed. This has had some impact but obviously not enough.

Defense Secretary Robert Gates wants to send 4,500 more American ground troops to Afghanistan — if they can be spared from the war in Iraq. But American commanders in Afghanistan have been pleading for months for about three times that number. NATO needs to step up its military efforts, and with other states build up Afghanistan’s security forces, administrative capacity and rural development.

NATO commanders are also trying to coordinate operations more closely with the Afghan military, giving it a bigger role in planning operations and conducting searches. These changes are welcome but long overdue.

We have similar concerns about Pakistan. This week, helicopter-borne American Special Operations forces attacked Qaeda militants in a Pakistani village near the Afghan border. At least one civilian, a child, was killed and possibly more in what may be the start of a new American offensive.

Pakistan’s political situation is extremely fragile, and anti-American sentiment there is fierce. Sending more American troops and planes into Pakistan’s lawless border regions might be worth the backlash if the mission apprehended a top Qaeda operative. That apparently did not happen this week.

Pakistan’s army, with intelligence help and carefully monitored financial support, should do most of the fighting. Asif Ali Zardari, expected to be Pakistan’s new president, has promised to work to defeat the Taliban and ensure that the country is not used for terrorist attacks.