Context. Strongly star-forming galaxies of subsolar metallicities are typical of the high-redshift universe. Here we therefore provide accurate data for two low-z analogs, the well-known low-metallicity emission-line galaxies Haro 11 and ESO 338-IG 004. Aims. Our main goal is to derive their spectroscopic properties and to examine whether a previously reported near-infrared (NIR) excess in Haro 11 can be confirmed. Methods. On the basis of Very Large Telescope/X-shooter spectroscopic observations in the wavelength range ∼λλ3000-24 000 Å, we use standard direct methods to derive physical conditions and element abundances. Furthermore, we use X-shooter data together with Spitzer observations in the mid-infrared range to attempt to find hidden star formation. Results. We derive interstellar oxygen abundances of 12 + log O/H = 8.33 ± 0.01, 8.10 ± 0.04, and 7.89 ± 0.01 in the two H ii regions B and C of Haro 11 and in ESO 338-IG 004, respectively. The observed fluxes of the hydrogen lines correspond to the theoretical recombination values after correction for extinction with a single value of the extinction coefficient C(Hβ) across the entire wavelength range from the near-ultraviolet to the NIR and mid-infrared for each of the studied H ii regions. Thus, we confirm our previous findings obtained for several low-metallicity emission-line galaxies (Mrk 59, II Zw 40, Mrk 71, Mrk 996, SBS 0335-052E, PHL 293B, and GRB HG 031203) that the extinction coefficient C(Hβ) is not higher in the NIR than in the optical range and therefore that there are no emission-line regions contributing to the line emission in the NIR range, which are hidden in the optical range. The agreement between the extinction-corrected and CLOUDY-predicted fluxes implies that a H ii region model including only stellar photoionisation is able to account for the observed fluxes, in both the optical and NIR ranges. No additional excitation mechanism such as shocks from stellar winds and supernova remnants is needed. All observed spectral energy distributions (SEDs) can be reproduced quite well across the whole wavelength range by model SEDs except for Haro 11B, where there is a continuum flux excess at wavelengths >1.6 μm. It is possible that one or more red supergiant stars are responsible for the NIR flux excess in Haro 11B. We find evidence of a luminous blue variable (LBV) star in Haro 11C.