The Turnbull government has retained its one-seat majority after won back the Sydney seat of Bennelong, despite a swing against him following a bitterly fought campaign.
Mr Alexander's victory against Labor's star candidate, former NSW premier Kristina Keneally, will come as a relief to Prime Minister Malcolm Turnbull.
With nearly 30,000 votes from 12 of 39 booths counted, Mr Alexander had won 54.71 per cent of the two-candidate preferred vote of Ms Keneally's 45.29 per cent.
He suffered a swing of 5.01 per cent, but it was nowhere near enough to overcome his margin of 9.7 per cent.
"There is no sign of a swing larger than that or significantly larger than that which could endanger the Liberal Party holding the seat and John Alexander will be re-elected," ABC election analyst Antony Green said.
Former Liberal senator Cory Bernardi's new party, Australian Conservatives is running a candidate, who has attracted around 4.7 per cent of the primary vote.
It appears most of Joram Richa's preferences have gone to Mr Alexander.
The by-election in the northwestern suburban electorate in Sydney was called after Mr Alexander resigned from parliament after he suspected he was a dual citizen.
Saturday's by-election became a tight contest after Labor took up the fight for the seat by selecting former Ms Keneally, and throwing big names and resources into its campaign.
But the by-election has been less about the candidates, and more about the future of the Turnbull government and Malcolm Turnbull's leadership.
A Liberal loss would have left the government with 75 seats, meaning the coalition would no longer have had a majority in the 150-seat House of Representatives.
Take your Radio, Podcasts and Music with you