Series of CCD long-slit spectra have been obtained in the 3600-10000 Å range, with the ESO 1.5m telescope, for the six brightest compact H ii regions in the LMC and SMC: N 11A, N 160 A1-A2 and N 88A, N 81 and N 26A-B, respectively. For each region the spectral type of its complex exciting source is given. From the emission-line intensities we have derived the gas electron density and temperature, and computed the chemical abundances of He, O, N, Ne, S, and Ar, which we compare with the ones found for other H ii regions in the Magellanic Clouds.