Hi, and thanks for your medical question on eHealth forum!
Erectile dysfunction is the inability to develop or maintain an erection of the penis sufficient for satisfactory sexual performance. Generally if there is any problem in the normal physiology of erection it can result in failure of erection, weak erection or early loss of erection. Many causes are there of which diabetes and low testosterone are the most important. Hence these should be eliminated first along with varicoceles. Other causes are stress and anxiety, depression, poor communication with your partner, unrealistic sexual expectations making sex a task rather than a pleasure, and fear of non performance based on previous experience. In your case the last reason appears to be the primary cause.
Smoking, alcohol, and illicit drugs can also be a cause. In your case may not be true. Medical conditions such as high blood pressure, poor circulation and peripheral vascular disease, heart or thyroid conditions, spinal cord injury, nerve damage (for example, from prostate surgery), or neurologic disorders (such as multiple sclerosis or Parkinson's disease) can all cause erection problems. Though these medical conditions may not be there in your case they need case they need to be ruled out one by one. Other than all this it could be injury to shaft of penis due to masturbation.
If you can masturbate and ejaculate, then there shouldn't be any medical problem. By learning relaxation techniques, you can overcome the stress of performance during sex. It would be wise to refrain from a sexual relationship for sometime, and undergo the tests to see if there is a medical problem. If there is one, it can be treated. If no medical cause is found, it will put your mind to rest. Then you can undergo counseling to overcome the fear. Hope this helps. Take care!