Your first sentence is an example of what you may have heard called the Third Conditional. It is used to express something that didn’t actually happen. Your second sentence, on the other hand, is an example of the Second Conditional, which expresses something that is still possible, but which is unlikely.
It’s easier to see the difference with sentences that are positive rather than negative, as these three examples may show.
First Conditional: 'If you run you will catch the train'. This predicts a likely event: running will certainly allow you to catch the train.
Second Conditional: 'If you ran, you would catch the train.' This suggests that the person addressed is unlikely to run.
Third Conditional: 'If you had run, you would have caught the train.' The person addressed didn’t run.