Lt. Gen. Zaheer ul-Islam, at right, will lead Pakistan’s spy agency, replacing Lt. Gen. Ahmed Shuja Pasha, who had been in charge since 2008. (STRINGER/REUTERS)

Pakistan’s powerful intelligence agency, perhaps the most crucial but least trusted player in the U.S.-led battle against militants in Afghanistan and Pakistan, has a new spymaster.

Prime Minister Yousuf Raza Gilani announced on Friday that Karachi-based Lt. Gen. Zaheer ul-Islam will head Inter-Services Intelligence (ISI), replacing Lt. Gen. Ahmed Shuja Pasha, who has led the agency since 2008 — and whose retirement may improve the troubled U.S.-Pakistan alliance against terrorism.

“Personal relationships with General Pasha have worn a bit thin,” said a former senior U.S. intelligence official who spoke on the condition of anonymity. “It might be good to start afresh.”

Pasha’s term already had been extended — unusual in the top echelons of the Pakistani military — so the appointment of a new spy chief was anticipated. Pasha had also faced criticism in the ranks for his perceived failures surrounding the U.S. operation to kill Osama bin Laden last May.

The U.S. counterterrorism community relies to a certain degree on the ISI to identify al-Qaeda and other Islamic militant targets in Pakistan’s tribal regions, especially in the CIA’s long-running drone war. But the U.S. decision not to inform Pakistan about the impending raid on bin Laden’s compound in the garrison town of Abbottabad spoke volumes about the degree to which Washington mistrusted its supposed ally’s spy agency and military.

Pasha’s successor was appointed the top military commander in the southern port city of Karachi in October 2010 — a post perceived as one of the army’s most important. Islam is close to the nation’s armed forces chief, Gen. Ashfaq Kayani; both served in the infantry in the army’s Punjab regiment.

Islam had also served as deputy director general of the ISI, in charge of domestic intelligence-gathering, according to military officials here.

A U.S. official who also spoke on the condition of anonymity noted that many of Islam’s army assignments had been focused on India but that he also had ties to the United States. “During his career, Zaheer traveled to the U.S. to participate in U.S. military-sponsored training and international fellowship programs,” the official said.

Although U.S. officials have often harshly criticized the ISI, accusing it of sheltering militants in Pakistan and tolerating their attacks on Western troops in Afghanistan, the change of leadership brings an opportunity to reset the relationship.

“We would expect General Zaheer to continue cooperation with the United States in our mutual fight against terrorism,” the U.S. official said. “It would not be a surprise to see a brief transition period as the new head of ISI gets up to speed, but that shouldn’t have much impact on counterterrorism cooperation.”

Pakistanis often refer to general officers, even in a formal context, by their rank and first name.

Relations between the CIA and ISI have been consistently strained. Last fall Adm. Mike Mullen, then chairman of the Joint Chiefs of Staff, publicly charged that the Haqqani network, the Pakistani-based militant organization U.S. forces in Afghanistan consider their most potent nemesis, was a “veritable arm” of the ISI. Although Pakistan has said it does not know the exact location of the network, U.S. intelligence officials maintain it has provided coordinates and photographs of Haqqani headquarters in the tribal region town of Miranshah, near a Pakistani military base and airstrip.

Despite the ruptured relationship, which snapped in November after Afghan-based U.S. aircraft inadvertently killed 24 Pakistani soldiers in a cross-border raid, Pasha has maintained cordial ties with the current CIA director, David H. Petraeus, and his predecessor, Leon E. Panetta. Even as Pakistani and U.S. diplomats and military commanders have remained at arm’s length since November, Pasha met secretly with Petraeus in a third country early last month.

Ties also neared a breaking point early last year when a CIA contractor, Raymond Davis, shot and killed two Pakistanis while driving through Lahore. Although the Pakistanis immediately labeled Davis an intelligence agent, the Obama administration insisted he was a diplomat working in the Lahore consulate and had diplomatic immunity. After two months of U.S. pressure, Pakistan allowed Davis to leave the country. The administration later acknowledged his CIA status.

Pakistan has charged the United States with placing numerous intelligence personnel inside the country without acknowledging their status, and has sporadically refused to issue visas to the CIA.

DeYoung reported from Washington. Special correspondent Shaiq Hussain in Islamabad contributed to this report.