The far right British National Party has failed in its bid to win a ninth council seat in Burnley.
Peter McCann's win meant the BNP is no longer the official opposition
Its narrow defeat, by just 11 votes to the Liberal Democrats, also means the BNP has lost its position as the official opposition on Burnley Borough Council.
The by-election was being closely watched, after the BNP won a third of the vote in May's local elections in the Lancashire town - its strongest ever result.
Lib Dem leader Charles Kennedy said: "I'm delighted voters in Burnley have chosen Peter McCann of the Liberal Democrats over Labour, and particularly, over the BNP and their unpleasant racist views."
Following May's result Trevor Phillips, chairman of the Commission for Racial Equality, said that special circumstances in the town, which suffered three race riots in 2001, had allowed the BNP to "creep in".
We must continue to find ways of reconnecting with those who have become
disillusioned and are tempted to vote for extremists like the BNP
Following Thursday's election, the BNP and the Lib Dems are now the joint second largest parties in the town.
The ruling Labour Party's majority was reduced to just one seat after its candidate in the Hapton With Park ward, former deputy leader of the council Andy Tatchell, was beaten into third place
The by-election was prompted by the resignation of a Labour councillor following the BNP's success in May.
Newly-elected Lib Dem councillor Peter McCann, who polled 788 votes against the 777 for BNP candidate Andrew Kenyon, was delighted with the result.
He said: "It is absolutely superb. It is a smashing result from a standing start.
The BNP's Andrew Kenyon lost by just 11 votes
"It has been four weeks of hard work and it was an excellent result."
Charles Kennedy said the Lib Dems would continue to fight the BNP.
He said: "We must continue to find ways of reconnecting with those who have become
disillusioned and are tempted to vote for extremists like the BNP."
The people standing for election were:
Alan Dean Marsden - Conservatives
Peter Rennie McCann - Liberal Democrats
Patricia Carol Stinton - Independent
Andrew John Tatchell - Labour Working For Hapton and Padiham