Cloud shadows are observed by the TROPOMI satellite instrument as a result of its high spatial resolution compared to its predecessor instruments. These shadows contaminate TROPOMI's air quality measurements, because shadows are generally not taken into account in the models that are used for aerosol and trace gas retrievals. If the shadows are to be removed from the data, or if shadows are to be studied, an automatic detection of the shadow pixels is needed. We present the Detection AlgoRithm for CLOud Shadows (DARCLOS) for TROPOMI, which is the first cloud shadow detection algorithm for a spaceborne spectrometer. DARCLOS raises potential cloud shadow flags (PCSFs), actual cloud shadow flags (ACSFs), and spectral cloud shadow flags (SCSFs). The PCSFs indicate the TROPOMI ground pixels that are potentially affected by cloud shadows based on a geometric consideration with safety margins. The ACSFs are a refinement of the PCSFs using spectral reflectance information of the PCSF pixels and identify the TROPOMI ground pixels that are confidently affected by cloud shadows. Because we find indications of the wavelength dependence of cloud shadow extents in the UV, the SCSF is a wavelength-dependent alternative for the ACSF at the wavelengths of TROPOMI's air quality retrievals. We validate the PCSF and ACSF with true-colour images made by the VIIRS instrument on board Suomi NPP orbiting in close proximity to TROPOMI on board Sentinel-5P. We find that the cloud evolution during the overpass time difference between TROPOMI and VIIRS complicates this validation strategy, implicating that an alternative cloud shadow detection approach using co-located VIIRS observations could be problematic. We conclude that the PCSF can be used to exclude cloud shadow contamination from TROPOMI data, while the ACSF and SCSF can be used to select pixels for the scientific analysis of cloud shadow effects.