The XL-Calibur balloon-borne hard X-ray polarimetry mission comprises a Compton-scattering polarimeter placed at the focal point of an X-ray mirror. The polarimeter is housed within a BGO anticoincidence shield, which is needed to mitigate the considerable background radiation present at the observation altitude of ∼40 km. This paper details the design, construction and testing of the anticoincidence shield, as well as the performance measured during the week-long maiden flight from Esrange Space Centre to the Canadian Northwest Territories in July 2022. The in-flight performance of the shield followed design expectations, with a veto threshold <100 keV and a measured background rate of ∼0.5 Hz (20–40 keV). This is compatible with the scientific goals of the mission, where %-level minimum detectable polarisation is sought for a Hz-level source rate.