This has happened before, of course. In 1974 (Feb) the Liberals surged during the last few weeks of the campaign, but fell quite a bit short of what many polls had predicted (the result was still seen as a triumph for the Liberals, of course - in that respect it's quite different to this election). In 1983, the Labour vote slumped halfway through the campaign to the apparent benefit of the Alliance; a lot of polls done on the last day had they ahead or level with Labour and up in the high 20s. Again, they fell short.
Well, they were basically level with Labour in 1983 on votes, so that comparison is far from apt.
It was mostly poor targeting on the Lib Dems' part. They didn't campaign as hard as they should have in their held seats and immediate targets, and they spent a lot of energy in too many distant targets. It's great that they're now serious challengers in odd places like Hull North and Ashfield, but if even half that effort had been spent in the 12 seats they lost, they'd be in a better position.