Two tricks and two suggestions.
Trick 1: Raise your chin.
I'm guessing that your posture while you play is, as with many guitarists, especially students, head-down over your instrument. This posture makes a tight curl from forehead, down the back of the neck, across the left shoulder down the back of the upper arm to the elbow, up the back of the forearm, across the back of the wrist, and up the hand.
Simply moving the center of mass of your head back over your shoulders and thus relieving some of the tension on the neck will also relieve some of the tension all down the arm. It literally introduces a little bit of slack into the soft-tissue circuit ending at your frets.
You might imagine that you're playing to an audience and hamming it up -- looking at them, playing right to them. That will get you to lift your face and open up your posture a bit.
Trick 2: Practice playing pianissimo. Part of what is going on in your fretting hand is a function of how vigorously you're working the strumming/picking hand. Fake out your fretting hand by getting the other hand to take it a bit easier.
Suggestion 1: If you're getting so tense playing difficult passages -- and I think I know exactly what you're talking about, I have the same issue playing harp, and it does a doozy on my tendons -- that suggests to me that you're fighting for control to play something at the edges of your dexterity. So maybe you need to slow those passages way down, and get them into your hands properly with more practice, before trying them at speed.
Suggestion 2: There are a couple of physiological disciplines that help musicians manage body tension better to reduce or eliminate RSIs. The two I've heard of are the Feldenkrais Method and the Alexander Technique. I know almost nothing about them, except that I know serious musicians who swear by them. You might want to take instruction in such a discipline. It will almost certainly cost money.