Context. The optical and ultraviolet emission lines of galaxies are widely used to distinguish star-forming (SF) galaxies from active galactic nuclei (AGNs). However, this type of diagnostic has some associated uncertainties, because AGNs can be of low luminosity and/or heavily obscured, and the optical emission lines may be dominated by a stellar component. On the other hand, and despite its limitations, X-ray emission can be used as a reliable tracer of luminous AGNs. Several well-studied examples exist where the optical diagnostics are indicative of SF galaxy, but the X-ray properties reveal the presence of an AGN. Aims. We aim to characterize the nature of galaxies whose optical emission line diagnostics are consistent with star formation, but whose X-ray properties strongly point towards the presence of an AGN. Understanding these sources is of particular importance in assessing the completeness of AGN samples derived from large galaxy surveys, selected solely on the basis of their optical spectral properties. Methods. We construct a large sample of 211 narrow emission line galaxies (NELGs, which have full widths at half maximum (FWHMs) H β emission line <1200 km s −1 ) from the SDSS-DR7 galaxy spectroscopic catalogue, for which we are able to construct a classical diagnostic diagram, [OIII]/H β versus [NII]/H α (hence z < 0.4), and that are also detected in the 2−10 keV X-ray band and present in the 2XMM X-ray source catalogue. This sample offers a large database by which to investigate potential mismatches between optical diagnostics and X-ray emission. Results. Among these 211 objects, which based on our selection criteria all are all at z < 0.4, we find that 145 galaxies are diagnosed as AGNs, having 2−10 keV X-ray luminosities that span a wide range, from 10 40 erg/s to above 10 44 erg/s. Out of the remaining 66 galaxies, which are instead diagnosed as "star-forming", we find a bimodal distribution in which 28 have X-ray luminosities in excess of 10 42 erg/s, large thickness parameters (T = F 2−10 keV /F [OIII] > 1) and large X-ray to optical flux ratios (X/O > 0.1), while the rest are consistent with being simply starforming galaxies. Those 28 galaxies exhibit the broadest H β line widths (FWHMs from ∼300 to 1200 km s −1 ), and their X-ray spectrum is steeper than average and often displays a soft excess. Conclusions. We therefore conclude that the population of X-ray luminous NELGs with optical lines consistent with those of a starforming galaxy (which represent 19% of our whole sample) is largely dominated by narrow line Seyfert 1s (NLS1s). The occurrence of such sources in the overall optically selected sample is small (<2%), hence the contamination of optically selected galaxies by NLS1s is very small.