Nawaz Sharif is back. And this time, it could be the culmination of a political journey that has seen him established as perhaps the country's only genuine statesman in a couple of generations.

To critics, he is an unreformed rightwinger, a conservative politician who allows his party to pander to the extremist Islamist fringe, an arrogant bully who recklessly threatens confrontation with other institutions, particularly the powerful army.

But Sharif is no longer the callow 30-year-old who got his start in politics as a protege of the dictator General Zia. Nor is he the wild confrontationist whose first two terms as prime minister came to premature ends because of his inability to pick his battles or learn to co-exist with other power centres.

Instead, a stint in jail under Musharraf, then exile and five years as the leader of the opposition to the Asif Ali Zardari-led PPP government appear to have mellowed Sharif. He is now a leader who understands that democratic continuity is indispensable. And he has set himself to mending two of the original fault lines in Pakistan: the civil-military divide and relations with India.

Taken together, strengthening the democratic project, nudging the civil-military imbalance in the right direction and seeking to reset ties with India would amount to a fundamental reorientation of the Pakistani state – a reorientation last engineered by General Zia for very different purposes and with disastrous results. Can Sharif do it? He has the necessary attributes: he is Punjabi, is genuinely popular and appears to have the courage of his convictions.

During the election campaign, Sharif demonstrated an equanimity that was beyond him in the 90s, the last time he ruled Pakistan. Furiously attacked from all sides by well-funded adversaries – the PPP, Imran Khan and the PTI, and the dregs of Musharraf's old party, the PML-Q – Sharif refused to descend into the mud pit, choosing instead to emphasise national economic challenges and the need for strong government.

When Khan's tumble brought his campaign to a premature end in the crucial last hours of an intense campaign, Sharif suspended his own campaigning for 24 hours in a gesture of goodwill – a significant concession given that Sharif's party feared that a late PTI surge threatened to eat into its share of the vote. This gives hope that Sharif will be a good custodian of the democratic project for the next five years. But can he tame the army, particularly when it comes to wresting away control of national security and foreign policy?

In this, Sharif may get some unexpected help from the army itself, which is almost certainly still wary of him but appears to have accepted a new role as first among equals rather than the unquestioned and predominant power within Pakistan. Sharif's first test could be the selection of General Kayani's successor. Ostensibly appointed by the prime minister, in practice the army chief is usually selected from a shortlist that the outgoing chief provides.

In the past, maverick civilian prime ministers, including Sharif, have installed their own favourites as army chief in an attempt to neutralise the army's political role – a move that has backfired, as Sharif himself learned when he was ousted by Musharraf in 1999; Musharraf having been handpicked by Sharif as an army chief unlikely to challenge him.

On India, Sharif has already shown his intentions, giving forthright interviews to Indian journalists in the last days of the campaign in which he talked of his desire to restart the peace process he initiated in the late 1990s. Sharif has now invited the Indian prime minister, Manmohan Singh, to visit Pakistan, perhaps even as a guest at his swearing-in ceremony early next month.

But what forthrightness and boldness can help secure, old tricks can fatally sabotage. Sharif dramatically hosted the first ever visit by an Indian prime minister, in 1999 – but the Pakistan army-initiated Kargil war a few months later scuppered that initiative. And like Sharif now, Zardari tried to reach out to India soon after coming to power in 2008 – but then came the Mumbai attacks, blamed on the army-friendly Lashkar-e-Taiba.

And there is another fault line that since Sharif was last prime minister has been threatening to suck both the Pakistani state and society into oblivion: militancy and violent extremism. On that present-day challenge, Sharif has said worryingly little.