Corrective: The practical immediate answer is to do another test, covering the same material. Burn an hour. Not the end of the world. Let students keep whichever grade they do better on. Use your judgment if you water down the re-exam or if you just cover very similar material and the kids get kicked in the ass (calibrated) on level of effort needed. But do warn them, if you are retaining the level of difficulty (say nothing if weakening it). But do advise them on how to effectively study for the re-test.
Preventive: I love Tom's suggestion, but another similar one. Don't do 3 exams per semester. Do one per week. Had a teacher, for two years in HS, pre-calc and calc, who did this. Every Friday was a 50-min test.
When I first encountered it, thought it was a lot and how do we cover the material. But it ended up working great. Just like homework problems are the most effective studying, tests are basically sets of compelled homework problems. The regular routine made things very easy to plan in my life. And having more moderate stakes (not high stakes like a final/midterm, not low stakes like turn in your homework) felt like a reasonable amount of stress.
By the way, this will also allow you to get better at calibrating things yourself (since you have more tests). And it makes a random poorly designed test less critical in students' end of grade experience (just "one of those things", like a stochastic variable in a trend). But those are tangential benefits. The main driver is better training of the trainees by having more evaluated performances.
I'm sure I will hear squawks about lost lecture time (from people paid to lecture, go figure), but there is more and more proof that people learn from practice (from doing) better than from hearing/observing. And tests are a performance by the student.