Mr Shorten claimed the entire swing to Labor was "attributable to Malcolm Turnbull and his rotten policies for this country" and that the ALP finished 2017 with "a most remarkable wind in its sails".
But only two so far have been members of the House of Representatives, where parties need a majority to form a government.
But with almost 40,000 votes from 25 of 39 booths counted, Mr Alexander had won 55.3 per cent of the two-candidate preferred vote of Ms Keneally's 44.67 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.
The conservative Liberal Party candidate John Alexander regained his Sydney electorate, defeating Kristina Keneally, the Las Vegas-born candidate for the center-left Labor Party who was once leader of the New South Wales state government.
The Australian government on Saturday won a crucial by-election that restores its tenuous grip on power that was threatened by a constitutional ban on dual citizens sitting in Parliament.
But the by-election has been less about the candidates, and more about the future of the Turnbull government and Malcolm Turnbull's leadership.
"If this result was replicated at a general election, we would see 24 to 28 seats fall.that would mean a Labor government and Bill Shorten as our prime minister", she said.
The by-election was triggered by the resignation of Mr Alexander, who quit after being caught up in the Parliamentary citizenship saga.
"You can not translate a by-election result in Bennelong across the whole nation", Mr Pyne said.
Deputy Prime Minister Barnaby Joyce recorded a thumping win in his seat of New England earlier this month.