Abstract: The majority of active galactic nuclei (AGNs) 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 AGNs. The XMM-Newton serendipitous source catalog, of which 3XMM-DR4 is the latest version, is the largest catalog of X-ray sources ever produced; it contains about half a million detections. These sources are mostly AGNs. We have derived X-ray spectral fits for very many 3XMM-DR4 sources (?114?000 observations, corresponding to ~77?000 unique sources), which contain more than 50 source photons per detector. Here, we use a subsample of ?1000 AGNs in the footprint of the SDSS area (covering 120 deg2) with available spectroscopic redshifts. We searched for highly obscured AGNs by applying an automated selection technique based on X-ray spectral analysis that is capable of efficiently selecting AGNs. The selection is based on the presence of either a) flat rest-frame spectra from a simple power-law fit; b) flat observed spectra from an absorbed power-law fit; c) an absorption turnover, indicative of a high rest-frame column density; or d) the presence of an Fe K? line with a large 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 1023 cm-2. Of these 28 AGNs, 15 are candidate Compton-thick AGNs on the basis of either a high column density, consistent within the 90% confidence level with NH> 1024 cm-2, or a large equivalent width (>500 eV) of the Fe K? line. Another six are associated with near-Compton-thick AGNs with column densities of ~ 5 × 1023 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 AGNs with an efficiency of 80%.