This can happen underwater as well as on the surface and can give you a feeling of running out of air or being short of breath. You should first STOP, BREATHE, THINK, and ACT.
Notify your buddy or dive professional to stop, and cease all activity. If there is a bare rock or something nearby you can hold without damaging it or any growth on it, steady yourself. Then, take a series of slow, full breaths to regain normal breathing patterns. When you have recovered, continue the dive but control your activity level.