Aims. We describe the methods used and the analysis performed in the frame of the Gaia data processing activities to produce the Gaia Data Release 2 (DR2) sample candidates with short-timescale variability together with associated parameters. Methods. The Gaia DR2 sample of candidates with short-timescale variability results from the investigation of the first 22 months of Gaia G per-CCD, GBP, and GRP photometry for a subsample of sources at the Gaia faint end (G ~ 16.5−20 mag). For this first short-timescale variability search exploiting Gaia data, we limited ourselves to the case of suspected rapid periodic variability. Our study combines fast-variability detection through variogram analysis, a high-frequency search by means of least-squares periodograms, and an empirical selection based on the investigation of specific sources seen through the Gaia eyes (e.g., known variables or visually identified objects with peculiar features in their light curves). The progressive definition, improvement, and validation of this selection criterion also benefited from supplementary ground-based photometric monitoring of a few tens of preliminary candidates with short-timescale variability, performed at the Flemish Mercator telescope in La Palma (Canary Islands, Spain) between August and November 2017. Results. As part of Gaia DR2, we publish a list of 3018 candidates with short-timescale variability, spread throughout the sky, with a false-positive rate of up to 10–20% in the Magellanic Clouds, and a more significant but justifiable contamination from longer-period variables between 19% and 50%, depending on the area of the sky. Although its completeness is limited to about 0.05%, this first sample of Gaia short-timescale variables recovers some very interesting known short-period variables, such as post-common envelope binaries or cataclysmic variables, and brings to light some fascinating, newly discovered variable sources. In the perspective of future Gaia data releases, several improvements of the short-timescale variability processing are considered, by enhancing the existing variogram and period-search algorithms or by classifying the identified variability candidates. Nonetheless, the encouraging outcome of our Gaia DR2 analysis demonstrates the power of this mission for such fast-variability studies, and opens great perspectives for this domain of astrophysics.