Challenger Sarah Olney bulldozed Mr Goldsmith out of the Commons, sweeping away his 23,015 majority to finish 1,872 votes ahead of him.
The Lib Dems poured resources into the contest as they successfully switched the focus of the campaign to Brexit in the staunchly Remain west London seat after Mr Goldsmith quit as a Tory MP to force the by-election so he could run as an anti-Heathrow expansion independent.
The result saw Ms Olney poll 20,510 votes to Mr Goldsmith's 18,638, on a turnout of 41,367, or 53.6%.
Dominic Stockford of the Christian Peoples Alliance came sixth with just 164 votes. He only finished ahead of two independents.
Stockford lost his deposit because he only tallied 0.40 per cent of the vote.
The Lib Dem victor, who took 49.7 per cent of the vote, said the outcome had sent a "shockwave" through Downing Street and paved the way for Parliament to "override" the EU withdrawal referendum result.
"It does look now as if we can have a vote in Parliament that might override the referendum. And I will, obviously, be voting to Remain because that is always what I have believed," she told Sky News.
Asked if she would actively resist Brexit as an MP, she said: "Absolutely. Now I've been given this mandate."
A Conservative Party spokesman said the result would make no difference to Brexit plans, stating: "This result doesn't change anything. The Government remains committed to leaving the European Union and triggering Article 50 by the end of March next year."