ISLAMABAD, Pakistan (AP) -- When former parliament speaker Yousaf Raza Gilani was first tipped as a contender to be prime minister, he quipped that taking high office in Pakistan's cutthroat politics could fast-track him back to prison.
But in a sign of how fast political winds can change in a country that has seesawed for six decades between military and civilian rule, Gilani took the oath Tuesday as the new government chief.
For the 55-year old loyalist of slain opposition leader Benazir Bhutto it is a stunning comeback after five years behind bars under the regime of President Pervez Musharraf -- the man who swore him in as prime minister.
"We didn't get this moment for free. This moment came due to continued struggle and martyrdom," Gilani said Monday after being elected premier by a huge majority in parliament.
Bhutto's party has roared back to power after finishing first in Feb. 18 elections. It will lead a coalition government committed to reducing Musharraf's already diminished powers.
Gilani appears suited to that role _ not because of his political clout but his low-key pragmatism. Real power will lie elsewhere.
Bhutto's widower, Asif Ali Zardari, took charge of the Pakistan People's Party after her assassination in December, but cannot be prime minister because he is not a parliamentarian.
Some observers expect him to run for parliament in a by-election as soon as May and push Gilani aside, though Zardari denies that he covets the job.
And the second-largest party in the anti-Musharraf front is led by Nawaz Sharif, who was a powerful head of government until his ouster in Musharraf's 1999 military coup.
A well-connected member of Pakistan's narrow and wealthy elite, Gilani has earned the respect of both of today's political kingpins in a 30-year political career with plenty of twists and turns.
He hails from a landowning family in the Punjab city of Multan and entered politics in 1978 on the death of his father, a signatory of the Pakistan Declaration, which hastened the country's creation in 1947.
Gilani won a seat in parliament in 1985 during the dictatorship of Gen. Zia-ul Haq and served as a minister. He switched to Bhutto's party after Haq's death in a mysterious plane crash and defeated Sharif, then the chief minister of Punjab province, in a Lahore constituency in 1998.
He was a minister in Bhutto's first Cabinet and, during her second tenure from 1993 to 1996, served in the pivotal post of parliamentary speaker.
That period was a low point in Pakistan's failed experiments with democracy, with Sharif and Bhutto persecuting each other when in power and seeking to paralyze parliament when in opposition.
But Gilani, a tall friendly looking man usually seen in a smart Western business suit, acquired a reputation for evenhandedness as his fellow lawmakers traded insults and even physical attacks in the aisles of the lower house.
For instance, Gilani called on several occasions for Sheikh Rashid, a sharp-tongued critic of Bhutto, to be released from prison so that he could take his seat in parliament.
"He was fair," recalls Rashid, who switched allegiance from Sharif to Musharraf after the coup. "He called me to join the session but Benazir overruled him and I stayed in prison."
Musharraf vowed after the coup to sweep away a political class that he accused of leaving Pakistan on the brink of bankruptcy. Gilani was one of scores targeted in an anti-corruption drive.
But Musharraf last year ordered courts to quash charges still pending from that era in a bid to smooth Pakistan's return to democracy _ a move that his critics say amounts to an admission that the accusations were politically motivated.
Gilani was arrested in 2001, accused of cronyism in appointments and abusing his privileges during his time as parliamentary speaker, and was convicted the following year of abusing his authority.
He was held inAdiala Jail, the grim penitentiary in Rawalpindi where Zardari was also locked up for years on corruption charges.
Gilani's nephew, Zain Mujtaba Gilani, recalls that his uncle was badly shaken when he returned home on brief parole from Adiala for the funerals of his mother and sister.
On both occasions, Zain said Gilani told close relatives over dinner of how Musharraf envoys had approached him with offers to free him if he "shook hands" with the government.
He was eventually freed in 2006 after a higher court overturned the conviction. "My uncle refused and never compromised on his principles," Zain said.
Zain insisted his uncle, who is married and has five children, remained a "humble man." He said Gilani still goes into the hot, bustling city of Multan when his carefully brushed hair or thick mustache need a trim, rather than summoning the barber to his home.
Before his weekend nomination, Gilani had used his ex-jailbird status to dampen speculation that he would lead the new government. The palatial prime minister's office in the capital, he noted wryly, was "only a short distance" from Adiala.
But Zardari has long viewed Gilani as leadership material.
Zardari was in court to witness Gilani's 2001 conviction, and according to Sen. Babar Awan, who was defending Zardari in another case, made an uncanny forecast as the judge made his ruling.