Aims. We analyse particle, radio, and X-ray observations during the first relativistic proton event of solar cycle 25 detected on Earth. The aim is to gain insight into the relationship between relativistic solar particles detected in space and the processes of acceleration and propagation in solar eruptive events. Methods. To this end, we used ground-based neutron monitor measurements of relativistic nucleons and space-borne measurements of electrons with similar speed to determine the arrival times of the first particles at 1 AU and to infer their solar release times. We compared the release times with the time histories of non-thermal electrons in the solar atmosphere and their escape to interplanetary space, as traced by radio spectra and X-ray light curves and images. Results. Non-thermal electrons in the corona are found to be accelerated in different regions. Some are confined in closed magnetic structures expanding during the course of the event. Three episodes of electron escape to the interplanetary space are revealed by groups of decametric-to-kilometric type III bursts. The first group appears on the low-frequency side of a type II burst produced by a coronal shock wave. The two latter groups are accompanied at higher frequencies by bursts with rapid drifts to both lower and higher frequencies (forward- or reverse-drifting bursts). They are produced by electron beams that propagate both sunward and anti-sunward. The first relativistic electrons and nucleons observed near Earth are released with the third group of type III bursts, more than ten minutes after the first signatures of non-thermal electrons and of the formation of the shock wave in the corona. Although the eruptive active region is near the central meridian, several tens of degrees east of the footpoint of the nominal Parker spiral to the Earth, the kilometric spectrum of the type III bursts and the in situ detection of Langmuir waves demonstrate a direct magnetic connection between the L1 Lagrange point and the field lines onto which the electron beams are released at the Sun. Conclusions. We interpret the forward- and reverse-drifting radio bursts as evidence of reconnection between the closed expanding magnetic structures of an erupting flux rope and ambient open magnetic field lines. We discuss the origin of relativistic particles near the Earth across two scenarios: (1) acceleration at the CME-driven shock as it intercepts interplanetary magnetic field lines rooted in the western solar hemisphere and (2) an alternative where the relativistic particles are initially confined in the erupting magnetic fields and get access to the open field lines to the Earth through these reconnection events.