Scott Morrison remains Australia's prime minister after a surprise narrow victory, while Bill Shorten will quit as Labor's leader.
The coalition is edging closer to the 76 seats it needs to have a majority in the parliament, with 74 at the end of counting on Saturday night. Labor was on 66.
The result defies months of opinion polls, including an exit poll taken from voters on Saturday afternoon, which consistently showed Labor ahead.
"I have always believed in miracles," a jubilant Mr Morrison told Liberal Party supporters in Sydney just after midnight.
He said it was a victory for the "quiet Australians".
"Tonight is not about me or it's not about even the Liberal Party. Tonight is about every single Australian who depends on their government to put them first."
Labor bled votes in Queensland, NSW and Tasmania while a relatively strong showing from One Nation and Clive Palmer's United Australia Party helped the coalition.
Mr Shorten conceded his party would not be able to form government.
"I wish we could have won for the true believers, for our brothers and sisters in the mighty trade union movement. I wish we could have done it for Bob," he said, referring to the Labor legend and former prime minister who died on Thursday night.
But he urged Labor supporters to keep faith and carry on the fight.
"We are a resilient and proud movement and we never give up."
He will step down from the leadership but stay on in parliament.
Senior frontbencher Anthony Albanese will run for the leadership and other potential contenders include deputy leader Tanya Plibersek and shadow treasurer Chris Bowen.
Mr Morrison has been lauded as a Liberal hero who will now likely be able to lead the party in any direction he wants.
Senior Liberal strategist and senator Arthur Sinodinos says that should include borrowing parts of Labor's ambitious policy agenda and re-thinking climate policy.
One of the biggest losers of the night was former prime minister Tony Abbott, who lost his seat of Warringah to high profile independent Zali Steggall
Electoral commission staff counted about 11.5 million House of Representatives and 7.5 million Senate votes on Saturday night.
One Nation's Malcolm Roberts and independent Jacqui Lambie will return to the Senate, but Mr Palmer appears to have missed out despite spending millions on advertising.
Counting will continue on Sunday.
Australian Associated Press