It seems possible to me that many voters were determined this was just to replace a disgraced Labour MP with another Labour MP, without considering the record of the party on the main national issue. Too few had the courage to change their vote in order to support genuine exit from the EU.
From the BP's viewpoint though, this is a blow. Instead of showing that they can be elected, and thus encouraging others to find the nerve to vote for them in the next GE, they show, as the Liberals have tended to for years, that they can come a close second and let some other party in. They need to carefully consider how to turn that image around asap.