The majority of active galactic nuclei (AGN) are obscured by large amounts of absorbing material that makes them invisible at many wavelengths. X-rays, given their penetrating power, provide the most secure way for finding these AGN. The XMM-Newton serendipitous source catalog is the largest catalog of X-ray sources ever produced; it contains about half a million detections. These sources are mostly AGN. We have derived X-ray spectral fits for very many 3XMM-DR4 sources ($gtrsim$ 114 000 observations, corresponding to $sim$ 77 000 unique sources), which contain more than 50 source photons per detector. Here, we use a subsample of $simeq$ 1000 AGN in the footprint of the SDSS area (covering 120 deg$^2$) with available spectroscopic redshifts. We searched for highly obscured AGN by applying an automated selection technique based on X-ray spectral analysis that is capable of efficiently selecting AGN. The selection is based on the presence of either a) flat rest-frame spectra; b) flat observed spectra; c) an absorption turnover, indicative of a high rest-frame column density; or d) an Fe K$alpha$ line with an equivalent width > 500 eV. We found 81 highly obscured candidate sources. Subsequent detailed manual spectral fits revealed that 28 of them are heavily absorbed by column densities higher than 10$^{23}$ cm$^{-2}$. Of these 28 AGN, 15 are candidate Compton-thick AGN on the basis of either a high column density, consistent within the 90% confidence level with N$_{rm H}$ $>$10$^{24}$ cm$^{-2}$, or a large equivalent width (>500 eV) of the Fe K$alpha$ line. Another six are associated with near-Compton-thick AGN with column densities of $sim$ 5$times$10$^{23}$ cm$^{-2}$. A combination of selection criteria a) and c) for low-quality spectra, and a) and d) for medium- to high-quality spectra, pinpoint highly absorbed AGN with an efficiency of 80%.