The powerful head of Pakistan’s army said Sunday that he will retire at the end of November, clearing the way for Prime Minister Nawaz Sharif to select a replacement while maintaining the balance of power between civilian and military leadership.

With his term extended once in 2010, Gen. Ashfaq Kayani had been widely expected for months to give up control of the country’s nuclear-armed forces after six years on the job. But there had been mounting speculation that Sharif, who began his third term in June, could keep Kayani in a senior military position amid growing uncertainty about the region’s future.

Pakistan is facing relentless terrorist attacks from Islamist militants, continued tension on its eastern border with India and uncertainty over the long-term stability of neighboring Afghanistan as U.S. forces prepare to withdraw next year.

Appointed in 2007 by military ruler Pervez Musharraf, Kayani is widely viewed as a deft leader, popular in Pakistan as well as in world capitals, including Washington. And with Sharif still trying to navigate the historically tenuous relationship between Pakistan’s government and military, there was some doubt about how easily Kayani would cede the vast authority that comes with managing the wealthy, 520,000-member army.

But in a statement Sunday, the 61-year-old general said he would step aside so that Pakistan can continue to progress toward a stable, functional democracy.

The powerful head of Pakistan’s army, Gen. Ashfaq Kayani, says he will retire at the end of November 2013, clearing the way for Prime Minister Nawaz Sharif to select a replacement while maintaining the balance of power between civilian and military leadership. (Mohammad Yousaf/AP)

“As I complete my tenure, the will of the people has taken root and a constitutional order is in place,” Kayani said. “The armed forces of Pakistan fully support and want to strengthen this democratic order.”

Under military rule for much of its 66-year history, Pakistan has long struggled to strike a balance between its elected leaders and its military. There have been three successful military coups in Pakistan, including the one led by Musharraf in 1999 that resulted in Sharif being ousted from his second term and exiled to Saudi Arabia.

In May, Sharif was returned to power in a historic national election that marked the first transfer of power from one democratically elected government to another.

When Sharif was sworn in in early June, many analysts feared an awkward, perhaps confrontational, relationship between him and the country’s military.

Those fears have not materialized, as both Sharif and senior military leaders have worked to try to convey a unified, civilian command. Sharif, for example, has been given latitude to seek peace talks with the country’s longtime adversary, India.

Pakistan’s military has also largely yielded to Sharif’s goal of holding peace talks with the Taliban, though the army’s support for such talks was tested two weeks ago after the Taliban took credit for killing a Pakistan army general near the country’s border with Afghanistan.

Sharif could pick a new military chief from a list of three names suggested by Kayani, most likely based on seniority of existing three-star generals. But he could also opt for a less senior commander whom he trusts.

Several Pakistani media outlets have identified Lt. Gen. ­Rashad Mahmood, the current chief of the general staff, as the leading contender for the job. Sharif’s government has declined to comment on the speculation.

U.S. officials do not appear to have a favored candidate, and most observers expect Pakistan’s new military chief will continue to strive for amicable relations with the Pentagon. Relations between the countries frayed after the U.S. military, without notifying Pakistan’s military, traveled deep inside the country’s borders to kill Osama bin Laden in 2011. But leaders in Islamabad and Washington say they plan to work closely together in the coming years to try to ensure stability in Afghanistan.

“The feeling here is that [Kayani] is someone they know, and the importance of that relationship can’t be underestimated,” said Marvin Weinbaum, a senior scholar at the Washington-based Middle East Institute. “But I haven’t heard there is any particular concern it is likely to be anyone they ought to be worried about, either.”

Both Weinbaum and Ejaz Haider, a Pakistan-based security consultant and commentator, also noted that Kayani would have risked a backlash from within Pakistan’s military command had he tried to stick around past the end of his term.

“Pakistan’s military is a highly trained force and institution, so if he tried to say, ‘I am the only one who can handle that and no one else can,’ that is a rather poor reflection on the institution,” Haider said. “There should always be someone else for that job.”

Shaiq Hussain contributed to this report.