Australian Prime Minister Scott Morrison has thanked voters for re-electing his conservative coalition in a shock result at the federal polls.
He told supporters he had "always believed in miracles" as partial results showed the Liberal-National Coalition close to a majority.
Opposition Labor Party leader Bill Shorten has announced he is resigning after accepting defeat.
Exit polls had suggested a narrow Labor win for the first time in six years.
The final result of the election may not be known for some hours, but with more than 70% of votes counted the Coalition has won, or is ahead in, 74 seats in its quest for a 76-seat majority, with Labor on just 66 seats.
Australia has mandatory voting and a record 16.4 million voters enrolled for the election, which returns a new House of Representatives and just over half of the seats in the Senate.
The result nobody predicted
By Hywel Griffith, BBC Sydney correspondent
Try finding someone who says they saw this result coming.
For well over two years, the coalition has trailed behind Labor in the opinion polls, and the assumption had been it would be Labor's turn to govern.
But somehow Scott Morrison managed to turn things around at the 11th hour - and he did it largely on his own.
With some of his cabinet colleagues considered too toxic to appear in public on the campaign trail, ScoMo made this election about him, and his ability to be the trustworthy, daggy-dad Australia needed.
In the end, it was very, very close, but the voters decided, on balance, he deserved the fair go he craved.
What are the leaders saying?
"It is obvious that Labor will not be able to form the next government," Mr Shorten told Labor Party members.
He said he had called Mr Morrison to congratulate him, and announced he would not stand for re-election as Labor leader.
Thanking his opponent, Mr Morrison paid tribute to "the quiet Australians" who had voted for the Coalition.
"It has been those Australians who have worked hard every day, they have their dreams, they have their aspirations, to get a job, to get an apprenticeship, to start a business, to meet someone amazing," he said.
"To start a family, to buy a home, to work hard and provide the best you can for your kids. To save for your retirement. These are the quiet Australians who have won a great victory tonight!"
"I said that I was going to burn for you, and I am, every single day," he added.
Mr Morrison's second-in-command, Treasurer Josh Frydenberg, fought off a strong challenge for his seat in Melbourne. He attributed the Coalition's success to "the economic choice" made by voters.
In Sydney, Liberal supporter Greg Napper summed up the mood for Reuters news agency: "I thought I was coming to a wake, to be quite honest with you. This is a party - the results are encouraging."
Why was the election important?
Australia holds elections every three years but, with infighting rife, no prime minister has succeeded in serving a full term since 2007.
Mr Morrison said he had united his government - a coalition between his Liberal Party and its traditional ally the National Party - in the nine months since he replaced Malcolm Turnbull.
Surveys showed that the economy, cost of living, environment and health were central concerns for voters, while younger people in particular voiced frustration about climate change and a lack of affordable housing.
Mr Morrison campaigned primarily on economic issues, often doing so alone while painting the election as a choice between himself and Mr Shorten.
Mr Shorten promised to cut tax breaks for the wealthy and to lower greenhouse gas emissions.
There were fierce debates about the rolling leadership turmoil, formal recognition of indigenous Australians, and the treatment of female MPs in parliament.
"I think people have become afraid after a very negative campaign," Labor supporter Julie Nelson told Reuters at the party's Melbourne election night function. "They [the Liberals] managed to convince people they should be afraid of change."
Who lost their seats?
Former Liberal Prime Minister Tony Abbott conceded he had lost his seat in Warringah to former Olympic skier Zali Steggall.
"I can't say that it doesn't hurt to lose," he told supporters, but added: "I'd rather be a loser than a quitter."
In another development, controversial right-winger Fraser Anning failed to regain his Senate seat.
While in the Senate, he had called for preference to be given to white immigrants, used the Nazi-related phrase "final solution" while discussing immigration, and blamed the Christchurch shootings on Muslim immigration.
How did the vote work?
Australian elections always take place on Saturdays. This time about 7,000 polling stations were set up across the nation, the Australian Electoral Commission (AEC) said.
But people could vote early at pre-polling stations, and a record number - more than four million people - elected to do so in 2019.
Because voting is compulsory, anyone aged over 18 faces a A$20 (£11; $14) fine for not taking part.
At the last election, 95% of Australians voted - a much higher proportion than the most recent US (55%) and UK (69%) polls.
Also vying for support were minor parties including the Greens, One Nation and the United Australia Party, as well as a raft of independents.
If you have a question about the Australian election you can send it to us via the form below.
If you are reading this page and can't see the form you will need to visit the mobile version of the BBC website to submit your question.