ISLAMABAD - During a surprise visit to Afghanistan Thursday, U.S. Defense Secretary Leon Panetta said that Washington is running out of patience with neighboring Pakistan, where Taliban, al-Qaida and Haqqani militants have safe havens.

Relations between the Washington and Islamabad have been strained for the last six months. The United States feels Pakistan could do a lot more to shut down insurgent networks that use its territory to plan, direct and conduct cross-border attacks in Afghanistan, killing Afghan and U.S. troops.

Panetta’s strong words came barely two weeks after the latest attack against a U.S. base called Salerno, in Afghanistan’s Khost province, near the Pakistan border. Panetta blamed members of the Pakistan-based Haqqani network for the assault.

“It’s an intolerable situation, to have those attacking our forces have the convenience of being able to return to a safe haven in Pakistan,” said Panetta.

Speaking at a joint news conference at with Afghan Defense Minister General Abdul Rahim Wardak, Panetta said it was extremely important that Pakistan take action against the militants.

Pakistan’s government did not immediately react to Panetta’s statements.

The secretary made his unannounced trip to Afghanistan Thursday to take stock of the conflict as international forces prepare to start withdrawing troops. But he said peace in Afghanistan would in part depend on Pakistan. “We’ve made it very clear that it’s difficult to secure Afghanistan as long as there is a safe haven for terrorists in Pakistan,” he said.

U.S. officials say a recent drone strike in Pakistan’s North Waziristan tribal region killed al-Qaida’s number two leader, who was hiding there. Pakistan summoned U.S. diplomats to protest the ongoing campaign of drone strikes, saying they violate the country’s sovereignty.

Relations between the two countries have been tense since a U.S. airstrike last year killed 24 Pakistani soldiers stationed along the Afghan border. In protest, Pakistan demanded an apology and shut down NATO supply routes through its territory. Foreign troops in Afghanistan now rely more on an exit route through Central Asia in the north of Afghanistan, but it is much more costly.