Passive Q-switching or mode-locking by placing a saturable absorber inside the laser cavity is one of the most effective and popular techniques for pulse generation. However, most of the current saturable absorbers cannot work well in the visible spectral region, which seriously impedes the progress of passively Q-switched/mode-locked visible pulsed fibre lasers. Here, we report a kind of visible saturable absorber-two-dimensional transition-metal dichalcogenides (TMDs, e.g. WS2, MoS2, MoSe2), and successfully demonstrate compact red-light Q-switched praseodymium (Pr(3+))-doped all-fibre lasers. The passive Q-switching operation at 635 nm generates stable laser pulses with ∼200 ns pulse duration, 28.7 nJ pulse energy and repetition rate from 232 to 512 kHz. This achievement is attributed to the ultrafast saturable absorption of these layered TMDs in the visible region, as well as the compact and all-fibre laser-cavity design by coating a dielectric mirror on the fibre end facet. This work may open a new route for next-generation high-performance pulsed laser sources in the visible (even ultraviolet) range.