For six years, Pervez Ashfaq Kayani has been Pakistan’s chief of army staff, arguably making him the coup-prone country’s most powerful man.
The military is Pakistan’s best funded and most influential institution and has controlled the nation for more than half of its 66-year history.
Kayani came to power in 2007, after being appointed by the former military ruler General Pervez Musharraf.
Upon taking the job, he frequently travelled to conflict areas to meet his men who were fighting and dying in large numbers.
But like his predecessor, he also struggled to counter the threat of armed groups in the country’s lawless tribal areas.
Military analysts say this led Kayani to focus on what he saw as the true enemy of the nation.
In a speech earlier this year he did not name India - a country it has fought three wars with - as the only threat to Pakistan
"Today we are faced with internal as well as external challenges. The problems on our internal battlefront require our special attention because they pose a great threat every Pakistani," he said.
Under Kayani, the country faced its most significant threat in years.
In 2009, a faction of the Pakistani Taliban had taken control of the northern Swat region. In response, Kayani launched the defining military operation of his career.
Under his supervision, the Taliban was driven back into the remote tribal areas. But Kayani's popularity quickly sank in 2011.
That year began with the killing of two Pakistanis in the eastern city of Lahore by Raymond Davis, a CIA security contractor, and ended with an accidental air strike by US-led forces on a Pakistani border post that killed 24 soldiers.
Between those two crises was Kayani's greatest perceived failing - the Osama bin Laden raid.
Not because the Pakistani army failed to find the world's most wanted man, but because of the embarrassment caused when the US military launched its raid on Pakistani soil without Pakistan's knowledge.
The unilateral action spurred widespread anti-American protests and the military faced rare public criticism, directed mainly at Kayani.
He helped end the resulting tensions with Washington by making compromises with US military leaders.
Still, Pakistan's army chief never managed to quite give the Americans what they wanted - decisive action against the Haqqani network, a Pakistan-based armed group that regularly attacks US and NATO forces in Afghanistan.
Today Kayani retires against the backdrop of a historic civilian milestone.
In May, Pakistan held general elections, the country's first transition of power between two democratically elected governments through the ballot box.
The fact Kayani never tried to lead a coup against a democratically elected government appears to have helped his reputation to some degree.
But the Pakistani Taliban still controls important parts of the northern tribal areas, and remains an enduring threat.
And so, while Kayani is able to retire with some grace, he leaves behind him some unfinished business.