SYDNEY, Australia — Scott Morrison, Australia’s conservative prime minister, scored a surprise victory in federal elections on Saturday, propelled by a populist wave — the “quiet Australians,” he termed it — resembling the force that has upended politics in the United States, Britain and beyond.

The win stunned Australian election analysts — polls had pointed to a loss for Mr. Morrison’s coalition for months. But in the end, the prime minister confounded expectations suggesting that the country was ready for a change in course after six years of tumultuous leadership under the conservative political coalition.

“I have always believed in miracles,” Mr. Morrison said at his victory party in Sydney, adding, “Tonight is about every single Australian who depends on their government to put them first. And that is exactly what we are going to do.”

The election had presented Australia, a vital American ally in the Asia-Pacific, with a crucial question: Would it remain on a rightward path and stick with a political coalition that promised economic stability, jobs and cuts to immigration or choose greater action on climate change and income inequality?