Context. In recent years, HgMn stars have attracted attention after in several of them surface chemical spots of different elements were discovered, whose origin and possible connection with binarity and magnetic fields is not clear yet. Aims. We perform a complete study of the HgMn binary HD 161701, including the determination of physical parameters and photospheric chemical abundances. Methods. We analyzed time series of high-resolution spectroscopic observations obtained with ESO's spectrograph FEROS and the spectro-polarimeter HARPS, in addition to a near-IR spectrum obtained with CRIRES. Radial velocity curves for both stars were combined with additional spectroscopic information to estimate absolute stellar parameters. A spectral separation technique was applied, which enabled us to conduct a detailed spectral analysis of both the HgMn primary and the low-luminosity secondary component, which turned out to be a peculiar star as well. Chemical abundances were determined by spectral synthesis. Using HARPS and FEROS spectra obtained at 11 rotational phases, we detected line profile variations in both stellar companions, indicating a nonuniform surface distribution of chemical composition.