Context. The gamma-ray binary LS 5039 and the isolated pulsar PSR J1825−1446 were proposed to have been formed in the supernova remnant (SNR) G016.8−01.1. Aims. We aim to obtain the Galactic trajectory of LS 5039 and PSR J1825−1446 to find their origin in the Galaxy, and in particular to check their association with SNR G016.8−01.1 to restrict their age. Methods. By means of radio and optical observations we obtained the proper motion and the space velocity of the sources. Results. The proper motion of PSR J1825−1446 corresponds to a transverse space velocity of 690 km s −1 at a distance of 5 kpc. Its Galactic velocity at different distances is not compatible with the expected Galactic rotation. The velocity and characteristic age of PSR J1825−1446 make it incompatible with SNR G016.8−01.1. There are no clear OB associations or SNRs crossing the past trajectory of PSR J1825−1446. We estimate the age of the pulsar to be 80-245 kyr, which is compatible with its characteristic age. The proper motion of LS 5039 is μ α cos δ = 7.09 and μ δ = −8.82 mas yr −1 . The association of LS 5039 with SNR G016.8−01.1 is unlikely, although we cannot discard it. The system would have had to be formed in the association Ser OB2 (at 2.0 kpc) if the age of the system is 1.0-1.2 Myr, or in the association Sct OB3 (distance 1.5-2 kpc) for an age of 0.1-0.2 Myr. If the system were not formed close to Ser OB2, the pseudo-synchronization of the orbit would be unlikely. Conclusions. PSR J1825−1446 is a high-velocity isolated pulsar ejected from the Galaxy. The distance to LS 5039, which needs to be constrained by future astrometric missions such as Gaia, is a key parameter for restricting its origin and age.