NDP candidate Sheila Malcolmson has been declared the winner of a high-stakes byelection in Nanaimo, staving off a potential early election by preserving the party's slim minority in the B.C. Legislature.

With all polls reporting, Malcolmson had more than 49 per cent of the votes versus 40 per cent for BC Liberal candidate Tony Harris, beating him by 1,873 votes.

"Nanaimo was not election-fatigued, as it turns out," Malcolmson said to a room full of supporters at her campaign headquarters. "To all of you who worked so hard to make this happen, our positive message, the work that's been done to already lift people up in just a year-and-a-half, we're so encouraged to be able to keep that work on."

Malcolmson said she was ready to get to work immediately as a first time MLA.

"Starting tomorrow, we are building affordable housing, we are expanding child care, we are getting an urgent primary care centre. More doctors for people," she said, triggering cheers from the crowd. "We are standing up and protecting the coast, we are defending against the risk of expanded oil tankers, we are protecting from oil spills, we're protecting jobs doing it."

A former NDP MP, Malcolmson resigned from her federal seat of Nanaimo-Ladysmith in order to run for the provincial New Democrats.

Over at Harris' headquarters, the first-time Liberal candidate reflected on his campaign and thanked everyone who encouraged him to run.

"It's a process I thought I'd never go down, but I'm so happy that I did," he said, prompting chants of "Tony! Tony! Tony!"

"When we got into this thing everybody said there's just no chance. It's Nanaimo, right? So it's a campaign that we never should have even been in, but we were in, and we've been in the entire time," he said. "My objective with this was to change the conversation of our community, change the way that people think about the future not only of Nanaimo, but this region of our province north of the Malahat."

He said he hoped that the byelection would serve as a reminder to all political parties of how they can "open the hood and understand what this community's all about, and what they need to do here to move us forward."

A win in Nanaimo was considered crucial for the New Democrats, as a Liberal win would have given the party 43 seats – tying it with the 43 seats held by the NDP and Green party.

Green candidate Michele Ney captured more than seven per cent of the popular vote, and she and party leader Andrew Weaver issued a statement congratulating Malcolmson for her win.

“I’d like to congratulate MLA-elect Sheila Malcolmson,” she said. “I’m proud of the campaign that we ran in Nanaimo; it was principled and visionary. I am confident that tonight’s results speak to voters’ desire to see the government continue in partnership with the BC Greens."

Weaver said while the results for the Greens were disappointing, they were not unexpected.

"I can say with absolute certainty that our support exceeds the votes cast for the party today. I spent a lot of time in Nanaimo campaigning with Michele, and many members, donors and supporters of our party came up to us saying that while they continued to support our party, they felt they needed to vote for the NDP in this by-election so that the government and our agreement with them can continue," he said.

More than 9,300 voters turned out at advance polls, and more than 18,000 ballots were cast on election day out of an eligible 45,359 voters in the Nanaimo riding.

Voting line-ups were steady at 13 polling stations throughout the day Wednesday, with many calling it a chance to directly impact the make-up of the legislature.

"I've lived here for 52 years. Nanaimo has a chance to control the government for B.C., so I felt it was very important," one voter told CTV News.

Nearly 46,000 Nanaimo residents were able to vote Wednesday, but more were turned away due to confusion over who was eligible.

That prompted Elections BC officials to try to clear up the rules, saying only people who lived in the provincial electoral district were eligible to cast their ballots.

"I've taken quite a few phone calls from people…95 per cent of them have been very reasonable once we explain that the district only represents a part of Nanaimo and it's not the same as the entire city," said District Electoral Officer Patrick Maguire.

The byelection was triggered after former NDP MLA Leonard Krog resigned his seat last year upon being elected mayor of Nanaimo.

Live results of the byelection are available below: