Labour's Gareth Snell defeated UKIP leader Paul Nuttall in the Stoke-on-Trent Central by-election, winning by 7,853 votes to Nuttall's 5,233.
In his victory speech, Snell accused Nuttall of attempting to divide the constituency over the EU referendum.
"A city dubbed by some as the capital of Brexit has proved to the world that we are so much more than that," he said. "This city will not allow itself to be divided by the referendum... or by race or faith or creed."
"Those who came to Stoke-on-Trent to stoke hate and division and turn us against our neighbours, I have one simple message: you have failed...
"We have said with one voice that hate and bigotry is not welcome here."
Snell was the leader of Newcastle-under-Lyme Borough Council and has previously worked for former frontbencher Tristam Hunt and the Remain campaign in the referendum. Last year, Snell described Brexit as "a massive pile of sh*t".
Labour has held the Stoke seat for 67 years but was forced to defend it after Hunt resigned to take the position of director of London's Victoria & Albert Museum.
Although Snell saw off the challenge from Nuttall, who recently fell out of favour for admitting he had not lost personal friends in the Hillsborough disaster despite claims to the contrary, the Labour politician's career is not without controversy.
Earlier this year, Snell was forced to apologise for a series of abusive tweets aimed at women. A tweet from 2011 remerged in which the MP said Coronation Street's Deirdre Barlow should be given a "good slap".
In other tweets, he described media personality Janet Street-Porter as a "polished turd" and described a candidate on the BBC's The Apprentice as a "speccy blonde girl" and "f**king annoying".
He also described ITV's Loose Women as "squabbling sour-faced ladies".
In response, Snell said: "They were from years ago when I was tweeting along with TV programmes, but nevertheless, I shouldn't have tweeted those comments and I apologise for the offence they have caused."
He added he was a supporter of women's rights and said he had supported a local domestic violence project.