The general emergency telephone number in Spain is 112. Most chemists ('farmacia's') will have information about where you can go for emergency treatment and can provide information about which clinics and medical treatment you can get. If you suffer with a particular medical condition or allergic reaction to penicillin or other medicine, make sure you know what the Spanish translation for this is.
When calling out a doctor in an emergency, let them know that you have a
European Health Insurance Card (EHIC) and that you want to be treated under the EU arrangements, or inform them of your travel/health insurance details. If you are treated in a state medical centre (centro de salud) or out-patient clinic (ambulatorio) you will probably be referred to a state hospital for treatment, so carry details of your private medical insurance around with you.