The United States and its allies are winning in Afghanistan, the U.S. defence chief said on Wednesday, despite spreading violence, a resilient insurgency and uncertain prospects for a peace deal the West had hoped might end a decade of war.

I really think that for all the sacrifice that you're doing, the reality is that it's paying off, Defence Secretary Leon Panetta told U.S. soldiers at Forward Operating Base Sharana, an outpost in Afghanistan's eastern Paktika province.

We're moving in the right direction and we're winning this very tough conflict in Afghanistan.

Panetta struck an optimistic tone during much of his two-day holiday visit to Afghanistan, where U.S. commanders are charting a course to draw down the Western military footprint by 2014 and, they hope, finally conclude a long and costly war.

Panetta's visit to Paktika comes as the country's rugged east, where insurgents cross back and forth from lawless areas of western Pakistan, takes on increasing importance following the weakening of the Taliban in its southern heartland over the past 18 months.

Are there challenges out there? You're damn right there are challenges, Panetta said. Are we able to take on those challenges? You're damn right we are.

U.S. commanders such as Lieutenant General Curtis Scaparrotti say that President Barack Obama's decision to deploy more than 30,000 extra troops to Afghanistan helped reverse deteriorating security and handed the advantage to NATO forces.

In the south I believe we have delivered a tactical defeat to the Taliban, Scaparrotti, who heads day-to-day Afghan operations, told reporters in Kabul. We still have to consolidate that gain.

Yet many observers see the situation in Afghanistan very differently. The Taliban and their affiliates remain a potent enemy and poor governance, widespread poverty and rampant corruption raise questions about stability.

As the West withdraws, the Obama administration has embraced a political solution to the war. Officials are seeking a peace deal between the government in Kabul and the Taliban, but it is unclear whether the embryonic initiative will flourish.

MORE WORK TO DO

Speaking later in the day to U.S. diplomats in Kabul, Panetta struck a more circumspect tone, praising progress against the Taliban, but saying there was more work to do.

That is not to say that this mission is by any means accomplished - it's not, Panetta said.

U.S. officials are hoping to conclude a strategic partnership agreement with Afghanistan that would lay out, in principle, a U.S. military presence after 2014. But that document has been held up by disagreement over military night raids - which Karzai wants to end but which Western military officials say are critical - and other issues.

But perhaps the biggest challenge to the U.S. strategy in Afghanistan lies in Pakistan, where there is heavy insurgent activity along the colonial-era border.

Military officials in places like Paktika say insurgents are weaker than they once were, but their frustration is palpable as they grapple first-hand with a flow of fighters and weapons from across the long, mountainous border with Pakistan.

Tension between Pakistan and the United States has spiked since NATO aircraft killed two dozen Pakistani soldiers along the border last month in an attack NATO described as a tragic, unintended incident. Pakistan shut down a key NATO supply route in retaliation and refused to cooperate with an investigation.

That is unwelcome news for the likes of Colonel Edward Bohnemann, who commands U.S. troops seeking to secure Paktika province's 380-km (236-mile) border with Pakistan.

Because they cannot entirely choke off insurgent traffic across the unmarked, remote frontier, they have set up layers of defences including Afghan border guards and NATO soldiers.

There are too many goat trails, too many small roads to say we're going to put a hard stop (to insurgents) at the border, he said.

(Editing by Robert Birsel)