Good student but terrible test taker?
I too went through a period where I panicked when taking tests. I saw a psychologist for help. Even if you choose not to go that route, you might find my experience helpful.

The problem began when I started taking the kind of tests where even the best students may not be able to answer all of the questions. I'd look at question one, not know how to answer it (at least, not right away), and begin to get nervous. Question two might seem daunting as well, so I'd become even more nervous. By the time I'd looked at question three, I was convinced that I would fail. Eventually I might realise that I knew how to do part of one of the questions. That gave me confidence to tackle another piece of another question, and so on. But I spent too much time panicking to do well on most tests.

The key for me in overcoming this was to realise that it was normal to not know how to answer any of the questions at first. I learned to expect it, but also to expect that after a couple of minutes I would begin to get ideas for solutions. By expecting that I would draw a blank at first, while realising that this wouldn't mean I'd fail the test, I kept myself from panicking.

Part of what the psychologist did was to help me understand this. The other thing was that he worked with me to visualise the test-taking procedure:
sitting down at the desk, turning over the paper, scanning the list of questions, not knowing how to answer any of them, then getting an idea, and so on. He talked me through the scenario while I did some relaxation exercises that he taught me.

Take comfort in the fact that your test-taking days are almost over. After you get a postgraduate degree, no one cares whether you passed with flying colours or barely squeaked by. Your publications will be far more important.