HAMILTON -- For a few short weeks, Andrea Horwath appeared tantalizingly close to the Ontario premier's office -- a prize that proved elusive once again on Thursday for the veteran politician who has led the provincial New Democrats for almost a decade.

Despite failing to win government, Horwath's position is likely safe, experts said. She handily won her own seat and boosted her party's overall count significantly from the 18 seats at dissolution to 39 at latest count, good enough for official opposition status and rare heights for New Democrats in Ontario.

"Millions of people voted for change for the better," an upbeat Horwath told a crowd gathered at the Hamilton Convention Centre after the Progressive Conservatives won a majority. "We have won more seats than we have in a generation."

New Democrats rejected the politics of fear and cynicism, Horwath told the approving crowd, who chanted "NDP! NDP!" -- lending an air of victory to the second-place finish.

"I am humbled that Ontarians have asked us to serve as the new Official Opposition," a beaming Horwath told them.

In the crowd, Trudi Lorenz expressed disappointment at the Progressive Conservative win, saying she had hoped the NDP would have at least been able to form a minority government.

"I thought that this was our time," Lorenz said.

It was a mid-campaign surge in the polls, as the Progressive Conservatives under Doug Ford and incumbent Liberal Premier Kathleen Wynne struggled, that thrust Horwath, 55, into an unusual space for a New Democrat leader.

Horwath responded with increased confidence, engaging with audiences, parrying tougher media questions and rival attacks on her party, its candidates, and its platform. She said she had detected "anxiety" among voters.

Pundits said the NDP leader had tapped into the prevailing mood with a mostly sure-footed folksy pitch.

"Andrea Horwath projected a credible change agenda," Myer Siemiatycki, a political science professor at Ryerson University, said Thursday. "(She) capitalized well on the disapproval many Ontarians felt towards both (her rivals)."

The less fortunate, Horwath said repeatedly, were her priority. They were the ones who needed better access to health care and child care, were strained under high electricity rates, or couldn't find affordable housing, she said.

"Despite GDP growth, these problems continue to fester and yet the very well off continue to do very well," Horwath said in a recent interview. "My priority is balancing the family budget, making sure people have the services they need and the affordability on things like electricity and childcare and housing."

Only after that was done, she had said, would an NDP government move to balance the province's red-inked books by taxing the well-off.

However, Horwath's campaign also played into Ford's hands. He insisted an NDP government would inevitably mean reckless spending and higher taxes.

Voters appeared to agree, buying instead into Ford's promises to cut taxes and rein in government spending by finding billions in unspecified waste -- something Horwath failed to effectively counter.

Horwath failed to make a strong enough case to voters about the failings of the last Conservative government, such as recurring school strikes, and cuts to services and programs, Siemiatycki said.

Nor did she do enough, Siemiatycki said, to remind voters of the turmoil that occurred the last time Ford had a lead role in governing a jurisdiction, when his late brother Rob Ford was mayor of Toronto.

Paul Beyda, also at the convention centre, said Horwath did really well, despite failing to win the big prize.

"She won all the debates and was everybody's favourite candidate, but in the end that wasn't enough," Beyda said. "(But) the tide is turning in more of a right-wing direction."

Still, Horwath would prove highly effective as Opposition leader, observers said.

"You may get an opposition more grounded in the lives of 'ordinary Ontarians' than in the outrages of upper middle-class Ontarians who won't feel the material effects of a Ford premiership," Peter Graefe, a McMaster University political science professor said on Thursday. "Her folksy populism, if sustained, could be a very effective counter to Ford once Ford has to make trade-offs."

Horwath, a mother of one, did labour studies at Hamilton's McMaster University -- waitressing to make ends meet.

After three terms on Hamilton council, she jumped to provincial politics in a byelection in 2004, becoming NDP leader in 2009. She led the party to a strong showing in the 2011 election but a disappointing finish in 2014 that almost cost her the leadership.

"They don't call me the Steeltown Scrapper for nothing," Horwath said recently. "I know how to hold my own. I do know how to go to the mat."