The NDP's Sheila Malcolmson has won a critical byelection in Nanaimo, B.C., maintaining the party's delicate hold on power in the province.

The former federal NDP MP will replace Leonard Krog, the five-term NDP member of the legislature who resigned his seat last year after being elected mayor of Nanaimo.

Malcolmson won almost 50 per cent of the vote, according to preliminary results posted by Elections BC, with B.C. Liberals candidate Tony Harris polling a little over 40 per cent. B.C. Green Party candidate Michele Ney was third with just over seven per cent.

The results of the byelection on Vancouver Island maintain the status quo in the legislature, with the opposition Liberals holding 42 seats, just shy of the 44 held jointly by the NDP and the Green Party.

The Greens agreed to support the NDP after the provincial election of 2017, allowing them to form a minority government.

Supporters celebrate Sheila Malcolmson's victory in Nanaimo, B.C.'s byelection on Wednesday night. (Chad Hipolito/The Canadian Press)

The NDP has held the riding, where there are 45,359 registered voters, for 13 of the past 15 elections. The January vote means the winner will sit in the legislature for the winter session and the provincial budget, which will be announced in February.

'We've got a lot of work to do'

Standing next to B.C. Premier John Horgan in Nanaimo just before 10 p.m. PT, Malcolmson addressed her supporters, and thanked her campaign volunteers and voters.

"This is a victory for Nanaimo," she said, to cheers from the crowd.

"​Nanaimo is not election fatigued, as it turns out," she said, adding: "We've got a lot of work to do."

Watch Sheila Malcolmson's victory speech:

The NDP's Sheila Malcolmson addresses her supporters after winning a byelection in Nanaimo, B.C. 1:00

She touted the B.C. NDP's priorities, including protecting B.C.'s coast from oil tankers, increasing the number of doctors in the province, and improving access to childcare.

"We are ratcheting down climate change emissions in the most ambitious program North America has, and we are generating green jobs while doing it," she said.

"We have the strongest economy in the country right now but we have to make sure that economy is shared by everyone."

Malcolmson was elected in the federal Nanaimo-Ladysmith riding in 2015. She announced she'd be vacating her federal seat in Oct. 2018 to run in the byelection.

B.C. Liberal candidate Harris, a well-known Nanaimo businessman, thanked his campaign workers and said, "this wasn't a process I ever thought I'd go down, but I'm glad that I did."

Watch B.C. Liberal candidate Tony Harris address supporters:

B.C. Liberal candidate Tony Harris, a well-known Nanaimo businessman, thanks his supported after conceding the Nanaimo byelection. 0:56

"When we got in this thing, people said we've got no shot. It's Nanaimo," he said, standing beside party leader Andrew Wilkinson. He called the community the "love of his life."

In a statement sent on behalf of the B.C. Greens, Ney — a teacher and daughter of former Nanaimo mayor and provincial MLA Frank Ney — congratulated Malcolmson, writing "tonight's results speak to voters' desire to see the government continue in partnership with the B.C. Greens."

B.C. Green party leader Andrew Weaver wrote that "while disappointing, tonight's results were not unexpected, given the conversations we have had with Green voters over the past few weeks."

"I can say with absolute certainty that our support exceeds the votes cast for the party today."

According to Elections BC, 21,410 valid votes were cast in the byelection. There are 45,359 registered voters in the electoral district.

The results from 2,839 absentee ballots will be counted next week.