It is perfectly natural to get worked up when in that danger zone of sparring, especially if you are just beginning and don't have much confidence in yourself. Unless, your just a real roughnut to begin with, all martial artists go through this. Training yourself to cope in those situations (e.g. don't look away, maintain your technique) is just as imporant as learning clean technique.
In my opinion, the only solution is to build your confidence in your defence. If you can have faith in your defence then you can be in that danger zone and maintain your composure. The only way to build confidence in your defence is to use it whilst seeing attacks come at you. In sparring, you can set yourself the target of not being hit in the whole round. Don't throw any attacks yourself, just defend. Move around, making angles and changing the distance but always defend. You will be amazed at how much your vision in those situations improve. Once your attacks are feeling natural, you will probably find yourself throwing counter-attacks without even realising because your defence will also put you in a good position to fire back.
Remember that you can work your defence with focus mitts too (and to a lesser extent thai pads). When I am holding mitts I always incorporate a defence somewhere in the combo. It might start with a defence: parry the jab, throw your jab, cross. It might be incorporated into the combo: jab, cross, slip to the outside of the incooming cross, then fire your own cross back. Or you can finish with a defence: jab, cross, weave to the outside. Mix it up. A good pad holder will make everything flow beautifully. One thing that I have been doing recently, which has helped me a lot is to finish every round that I do on the pads with 30 seconds of defence against a continuous flurry. I finish the round exhausted, and then the pad holder starts throwing whatever they want and I just defend. If I can trust my defence when I'm buggered then I should be fine in most situations. I am now completely comfortable just sitting in the pocket and taking whatever is thrown at me. It is quite liberating for my overall confidence. Personally, I would rather have pristine defence than have pristine attack.
Most gyms (at least the ones I have trained at) do a lot of work on throwing attacks but often the only defence work done is in sparring. Personally I disagree with this.
Check out from 1:45 onwards of this vid:
YouTube - ‪Muay Thai Chaiya‬‏