The Tory candidate, Robert Courts, won the Witney constituency in Oxfordshire by 5,702 votes, with the party's vote share falling from 60 per cent in 2015 to 45 per cent, as the Lib Dems surged past Labour into second.
The Tory majority on the seat was slashed by nearly 20,000 votes.
Liz Leffman polled 11,611 votes as the Lib Dems' share rose from 7 per cent to 30 per cent.
Larry Sanders, the brother of US Democrat presidential runner Bernie Sanders, polled 1,363 votes for the Green Party and was in fourth place after Labour's Duncan Enright.
Also Read
Witney has had a Tory MP since its creation in 1983.
However, this timeCourts, a barrister and local councillor, saw the majority cut from the more than 25,000 votes Cameron won in the last year's general election.
In his acceptance speech, Courts paid tribute to Cameron as "a great prime minister and a brilliant MP" for the constituency, saying he would strive to "help and represent local people".
The by-election was called after Cameron stood down as an MP following June's Brexit vote and was seen as the first electoral test for the Conservatives since Theresa May succeeded him as Prime Minister in July.
The former television actress received an 85 per cent share of the vote in the seat, which was not contested by other major parties out of respect for Cox, who was shot and stabbed in her West Yorkshire constituency.
"I hope Jo will be proud tonight of our community. We have shown that we stand together with one voice choosing unity and hope," she said.
The remaining nine candidates all lost their 500 pound deposits as they did not receive a big enough share of the vote.
A man has been charged with murdering Cox and is awaiting trial.
Disclaimer: No Business Standard Journalist was involved in creation of this content