CTV News has declared New Democrat Sheila Malcolmson the winner of a high-stakes provincial byelection in Nanaimo, B.C., potentially sparing her party's fragile minority government from an early election.

Malcolmson had 10,538 votes in the initial count – about half of the votes cast and nearly 1,900 more than Liberal rival Tony Harris.

Green candidate Michele Ney had 1,579 votes.

Scroll down or click here for detailed results from Elections BC

"Our positive message, the work that's been done to already lift people up in just a year and half—we're so encouraged to be able to keep that work on and it would not have happened without you," Malcolmson said at the NDP's headquarters, thanking her supporters and staff as well as the other candidates who ran in the byelection.

The MLA-elect reiterated some of the party's campaign priorities, including building affordable housing and improving child care.

"We've got a lot of work left to do," she said. "We are going to work together to tackle the issues that we face. I am so honoured to have served with Leonard Krog as MLA. I'm so honoured to carry his work on."

With Malcolmson as the new MLA for Nanaimo, the NDP and Greens will have a combined 44 seats over the Liberals' 42, bolstering the government's hold on the legislature. The NDP and Green parties signed an agreement following the 2017 provincial election that toppled the Liberals and allowed the New Democrats to form a minority government.

Liberal win would have likely triggered early election

Had Harris won, the Liberals would have been tied with the NDP-Green alliance at 43 seats each.

This kind of deadlock would not automatically have caused the government to fall, but it would have led to the unconventional situation requiring the Speaker—typically a neutral role in the house—to cast a tie-breaking vote in order for any piece of legislation, including the budget, to pass or fail.

And with a weakened NDP minority even more vulnerable to a confidence vote, the stalemate would have likely sent British Columbians back to the polls for a provincial election sooner than later.

“It's a campaign we never should have been in, but we were in and we have been in this whole time,” Harris told his supporters after the byelection was declared in the NDP's favour.

“We’re growing, we’re important and I think we’ve really put Nanaimo on the map."

Premier John Horgan also made an appearance and NDP headquarters, thanking supporters and staff for their commitment during the campaign.

"With a candidate of Sheila's calibre and the hard work of the people in this room and right across the city, we have returned a New Democrat to Nanaimo," he said.

"The project continues. The government's on its way."

Who is Sheila Malcolmson?

Malcolmson served as the MP for Nanaimo-Ladysmith from 2015 until 2019.

The 52-year-old left federal politics to run in Wednesday's byelection, saying she wants to make sure the Liberals' policies she blames for the homelessness and affordable housing crises do not return to the province.

Her platform included a plan to revitalize forestry in the Nanaimo area in a bid to create jobs and boost the local economy.

Malcolmson has also served the chair of the Islands Trust Council where she pushed for fairer ferry service, marine safety and oil spill prevention measures.

Elections BC forced to clarify riding boundaries

The byelection saw some confusion at the polls about who could and couldn't cast a ballot.

Elections BC issued a reminder to residents on Wednesday afternoon about voter eligibility.

The Regional District of Nanaimo is larger than the electoral district by the same name. That means some people who consider themselves Nanaimo residents were not in fact eligible to vote in the Nanaimo byelection.

"People in the municipality but not in the electoral district have been coming to vote so we're just trying to get the message out," Elections BC spokeswoman Rebecca Penz told CTV News.

Uncertainty, scandal heading into byelection

The byelection was called after New Democrat Leonard Krog vacated his seat back in November to become the mayor of Nanaimo. Krog had been passed over for a cabinet position when his party formed government in 2017.

The Liberals announced Harris, a well-known local developer and businessperson, as their candidate in early November.

Malcolmson and Ney were officially named the candidates for their respective parties in mid-December.

Despite long being considered an NDP stronghold, the results of a Mainstreet Research poll released Monday put the Liberals up by more than 12 points over the NDP, sparking uncertainty about the riding's future.

But Premier John Horgan was quick to point out pollsters have been wrong before.

"They ask for snapshots in time," he said. "Whether that's accurate—that's something we'll find out on Wednesday."

More than 20 per cent Nanaimo's 40,000 registered voters hit the advance polls early last week, just a day after a bombshell report by B.C. Speaker Darryl Plecas accusing two senior officials of "flagrant overspending" sent shockwaves across the province.

Then-MLA hopefuls answered questions about the alleged overspending—most of which Plecas' report said happened under the Liberals—during an all-candidates meeting on Thursday.

And while Malcolmson blamed what she called the Liberals' "culture of entitlement" for the scandal, Harris stuck his party's line since Plecas' report became public: “I think it’s important we address this aggressively with all party support.”

With files from CTV Vancouver's Bhinder Sajan, Breanna Karstens-Smith and The Canadian Press

Live byelection results follow. Viewing this on our mobile beta site? Tap here for a compatible version.