West Australian Labor has held former premier Mark McGowan's seat in a by-election viewed as a test of new premier Roger Cook's leadership.
Mr Cook's popularity crashed in recent weeks according to a poll showing the Liberal party holds a 54 per cent to 46 per cent two-party preferred lead over Labor.
But it wasn't enough to unseat the party in Rockingham, south of Perth, where Mr McGowan's replacement, Magenta Marshall, was well ahead in the count late on Saturday with 49 per cent of the vote.
With about 55 per cent of votes counted at 10pm Saturday, Labor was headed toward a two-party preferred vote of 67 per cent.
The party's healthy margin of 37.7 per cent, forged by Mr McGowan's rockstar popularity in 2021 amid the COVID-19 pandemic, had been expected to fall.
Fractures had emerged in the party when Ms Marshall was selected as its candidate over Deputy Mayor of Rockingham Hayley Edwards, who ran against Ms Marshall as an independent.
Controversial Aboriginal heritage laws, the rising cost of living and housing shortages also added to Labor's woes in the run-up to the by-election, which was viewed as a test of Mr Cook and WA Liberal leader Libby Mettam's leaderships.
Liberal Party candidate Peter Hudson, who campaigned on crime, health care and inflationary pressures, was headed toward a two-party preferred vote of 33 per cent late on Saturday with 55 per cent of votes counted.
Rockingham is a coastal community about 50 kilometres south of Perth city, with some 30,000 voters registered.
Earlier on Saturday, Mr Cook said he expected some "resettling" of the vote amid a period of transition.
"It will be tight," he told reporters at a primary school polling station on Saturday.
"This comes at a particularly difficult time at the moment."
Political commentator Peter Kennedy said Labor had faced a bumpy road since Mr McGowan resigned in May citing exhaustion.
Mr Kennedy said the poll was an important test for both the new premier and WA Liberal leader Libby Mettam.
"It's the first time they've gone head-to-head," he said.
Liberal candidate Peter Hudson said Labor's decision to poll voters and modify how-to-vote cards showed the party had been "desperately worried".
He said the Cook government had not been listening on a range of issues.
Expecting a swing towards her candidate, Ms Mettam had been keen to cast the contest as a mid-term test of the Labor government.
"What is clear is that the WA Liberal Party are in for the fight," she said.
"We will take this fight right up to (the next election in) 2025 with a strong suite of election commitments, as well as a strong raft of very strong grassroots candidates like we have here in Peter Hudson."
Mr McGowan was re-elected in 2021 with 82.7 per cent of first-preference votes.
"I don't expect to have the same amount of support that Mark has had for the last 26 years," Ms Marshall said on Saturday.
Except for his first win in 1996, Mr McGowan won every election without the need for preferences.