Militants operating out of safe havens in Pakistan remain a major threat to Afghanistan but cooperation between NATO-led forces and the Pakistani military is increasing, U.S. Defence Secretary Robert Gates said on Friday.

Devastating floods over the past month have delayed Pakistan's military from going after militants in the Federally Administered Tribal Areas (FATA) and North Waziristan on Pakistan's porous northwestern border.

Afghanistan regularly blames Pakistan for allowing Islamist groups to flourish there, President Hamid Karzai describing them as a great threat to Afghan security.

Before leaving Afghanistan, Gates went south to Kandahar, the birthplace of the Taliban, to visit U.S. troops and described the Islamist militants as a resilient enemy.

He said he and Karzai agreed on the need for stepped up cooperation between the NATO-led International Security Assistance Force (ISAF) and the Pakistani military to get rid of insurgent sanctuaries.

Cooperation between the two is increasing and everybody understands that the sanctuaries on the other side of the border are a big problem, Gates told reporters.

However, Gates said the likelihood of direct U.S. military engagement in Pakistan was very low.

Unfortunately the flooding in Pakistan is probably going to delay any operations by the Pakistani army in North Waziristan for some period of time, he said.

But I think the solution here is ISAF, Afghan, Pakistani cooperation to take care of these targets, he said.

TOUGH FIGHT AHEAD

Almost 150,000 foreign troops are in Afghanistan after U.S. President Barack Obama ordered last year another 30,000 troops in a bid to turn the tide against the Taliban-led insurgency.

Violence is at its worst across Afghanistan since the Taliban were ousted by U.S.-led Afghan forces in late 2001, with civilian and military casualties at record levels despite the presence of so many foreign troops.

Obama, who will review the Afghan war strategy in December after mid-term Congressional elections the month before, has set July 2011 as the date to start a gradual troop withdrawal from Afghanistan if conditions on the ground allow.

U.S. military leaders, including General David Petraeus, commander of U.S. and NATO forces in Afghanistan, have this week sought to temper expectations of a large-scale pullout, saying it would start with a thinning out process and that some would be sent home while others would be reassigned to other districts.

Gates arrived in Afghanistan on Thursday from Baghdad, where he attended ceremonies to mark the end of U.S. combat operations there after seven years.

That milestone has shifted the U.S. military focus back onto Afghanistan at a time when the U.S. public, and even some within Obama's Democratic party, are becoming increasingly sceptical about whether the war is worth fighting.

Gates however was upbeat about the progress that had been made in recent months, particularly around Kandahar.

U.S. and other foreign troops have fought hard campaigns in Kandahar and neighbouring Helmand province over the past year, suffering more casualties as they push into a network of valleys and mountains seeking out Taliban fighters.

The past week has been especially difficult, with 20 U.S. soldiers killed in one four-day period.

Seven soldiers were killed in two roadside bomb attacks on Monday, the most effective weapon used by militants even though they are often indiscriminate and cause civilian casualties. Gates visited a base where the dead had been stationed.

You guys are in the forward foxhole and what makes a difference in this whole campaign is your success here in Kandahar city, he told the troops.

Unfortunately there are going to be more tough days ahead and you know that better than anybody, he said.

(Writing by Tim Gaynor; Editing by Paul Tait and Miral Fahmy)