TORONTO -- Premier Dalton McGuinty, currently the longest-serving premier in Canada, will be saying goodbye today as he relinquishes Ontario's top job after nine years.

After winning three elections -- a feat unmatched by the provincial Liberals in more than a century-- McGuinty is set to deliver his swan song following a grandiose tribute tonight at the former Maple Leaf Gardens in Toronto.

It's the same building where McGuinty was selected as the party's leader in 1996, after an all-night convention where the fourth-place candidate managed an upset victory.

His uncanny ability to beat the odds became a common theme for the so-called "accidental premier" over the course of his career.

When he first arrived at the Ontario legislature in 1990, the awkward lawyer was a far cry from the polished politician he is today. It took seven gruelling years in Opposition -- and one election defeat -- before McGuinty led the Liberals to victory in 2003.

Along the way, he honed a political style that saw the governing party through many of the obstacles they faced over the last nine years.

"Never too high, never too low" was McGuinty's mantra, an extension of his straight-laced, father-knows-best image.

Time and time again, people told him that it couldn't be done -- that he couldn't win a seat as a Liberal, that he couldn't win the leadership, that he couldn't win the election, he once remarked. Yet he managed to do all three.

But he surprised everyone in October, when he decided to step down amid a series of scandals that seemed insurmountable, even for him.

He'd alienated a powerful ally he'd courted for years -- Ontario's public school teachers -- by forcing a pay freeze to reduce the province's massive deficit. The unions declared war, vowing to withdraw their financial support and use their organizational might to defeat the self-described "education premier" in the next election.

They made good on their threat in a Sept. 6 byelection McGuinty orchestrated in an effort to win the one seat he needed to regain a majority government, putting boots on the ground in Kitchener-Waterloo to elect a New Democrat for the first time in the riding's history.

Adding to his troubles was a rare contempt motion over the cancellation of two gas plants in Liberal ridings -- at a cost to taxpayers of at least $230 million --and a criminal probe of the province's Ornge air ambulance service.

By tendering his resignation and shutting down the legislature, the 57-year-old premier bought time for his party to elect a new leader, mend its relationship with the unions and wipe the slate clean on the contempt motion.

McGuinty has defended his record, pointing out that he's leaving the province with better schools and health care, and an economy that's starting to get back on its feet thanks to Liberal efforts to spur growth.

But what McGuinty called progress also carried a heavy price, as government spending more than doubled and the red ink began to flow.

The premier argued Ontario had to borrow money when the global recession hit in 2009, like many other governments, to save jobs and stoke the embers of economic growth.

His advice for his successor is to keep fighting the deficit. Oh, and "don't screw it up."

Growing up in Ottawa as the eldest son in a large Catholic family, McGuinty helped his busy parents care for his nine younger siblings. He worked odd jobs through high school to help out, from hospital orderly to a counsellor at his father's summer camp.

As premier, McGuinty would often draw from his childhood to impart a political lesson about the responsibilities of leadership.

He studied science before turning to law. In 1980, he married his high-school sweetheart Terri, an elementary Catholic school teacher. Together, they had four children: Carleen, Dalton Jr., Liam and Connor.

McGuinty jumped into politics 22 years ago under tragic circumstances. His father Dalton Sr., an English professor and provincial politician, died suddenly while shovelling snow and his eldest son was recruited to succeed him in Ottawa South.

McGuinty often joked that he was selected because the election signs in the garage already had his name on them.

He won the seat, bucking a New Democrat tide that washed the Liberals out of office.

Despite his bland public persona, McGuinty managed to win the Liberal leadership after placing fourth in the first two ballots.

He spent the next seven years in political purgatory, failing to lead the Opposition Liberals to victory in the 1999 election with the Tories branding him as not ready for prime time.

But McGuinty rallied after some media grooming -- by the same Chicago consulting firm that helped Barack Obama win the U.S. presidency -- and rejigging of the party machinery.

In 2003, he beat the beleaguered Tories, who were dragged down by a series of scandals over the fatal shooting of an aboriginal protester, a deadly tainted water scandal and a massive blackout.

His credibility took a hit shortly after when he imposed a health-care premium of up to $900 per worker, despite signing a pledge during the campaign not to raise taxes. McGuinty insisted he had no choice because the Tories left a hidden $5.6 million deficit.

He did another flip-flop on taxes when Ontario was teetering on the brink of the global recession, combining the provincial sales tax with the federal goods and services tax after campaigning against the idea for years.

It showed that behind McGuinty's paternal image was a shrewd politician who was prepared to make unpopular decisions if he thought it was the right thing to do.

He plans to stay on as the MPP for Ottawa-South until the next election, but said he hasn't given much thought to what he might do next.

As for his legacy, McGuinty said he'll leave it to others to decide, that he's simply grateful for having the opportunity to serve his province.

Whether the embattled Liberals can beat the odds once again without their longtime leader is another chapter for the history books that has yet to be written.