Recent magnetic field surveys in O- and B-type stars revealed that about 10% of the core-hydrogen-burning massive stars host large-scale magnetic fields. The physical origin of these fields is highly debated. To identify and model the physical processes responsible for the generation of magnetic fields in massive stars, it is important to establish whether magnetic massive stars are found in very young star-forming regions or whether they are formed in close interacting binary systems. In the framework of our ESO Large Program, we carried out low-resolution spectropolarimetric observations with FORS2 in 2013 April of the three most massive central stars in the Trifid nebula, HD164492A, HD164492C, and HD164492D. These observations indicated a strong longitudinal magnetic field of about 500-600G in the poorly studied component HD164492C. To confirm this detection, we used HARPS in spectropolarimetric mode on two consecutive nights in 2013 June. Our HARPS observations confirmed the longitudinal magnetic field in HD164492C. Furthermore, the HARPS observations revealed that HD164492C cannot be considered as a single star as it possesses one or two companions. The spectral appearance indicates that the primary is most likely of spectral type B1-B1.5V. Since in both observing nights most spectral lines appear blended, it is currently unclear which components are magnetic. Long-term monitoring using high-resolution spectropolarimetry is necessary to separate the contribution of each component to the magnetic signal. Given the location of the system HD164492C in one of the youngest star formation regions, this system can be considered as a Rosetta Stone for our understanding of the origin of magnetic fields in massive stars.