A novel method is reported, whereby screen-printed electrodes (SPELs) are combined with dispersive liquid–liquid microextraction. In-situ ionic liquid (IL) formation was used as an extractant phase in the microextraction technique and proved to be a simple, fast and inexpensive analytical method. This approach uses miniaturized systems both in sample preparation and in the detection stage, helping to develop environmentally friendly analytical methods and portable devices to enable rapid and onsite measurement. The microextraction method is based on a simple metathesis reaction, in which a water-immiscible IL (1-hexyl-3-methylimidazolium bis[(trifluoromethyl)sulfonyl]imide, [Hmim][NTf2]) is formed from a water-miscible IL (1-hexyl-3-methylimidazolium chloride, [Hmim][Cl]) and an ion-exchange reagent (lithium bis[(trifluoromethyl)sulfonyl]imide, LiNTf2) in sample solutions. The explosive 2,4,6-trinitrotoluene (TNT) was used as a model analyte to develop the method. The electrochemical behavior of TNT in [Hmim][NTf2] has been studied in SPELs. The extraction method was first optimized by use of a two-step multivariate optimization strategy, using Plackett–Burman and central composite designs. The method was then evaluated under optimum conditions and a good level of linearity was obtained, with a correlation coefficient of 0.9990. Limits of detection and quantification were 7 μg L−1 and 9 μg L−1, respectively. The repeatability of the proposed method was evaluated at two different spiking levels (20 and 50 μg L−1), and coefficients of variation of 7 % and 5 % (n = 5) were obtained. Tap water and industrial wastewater were selected as real-world water samples to assess the applicability of the method.