Magnetars are the most strongly magnetized neutron stars, and one of the most promising targets for X-ray polarimetric measurements. We present here the first Imaging X-ray Polarimetry Explorer observation of the magnetar 1RXS J170849.0-400910, jointly analyzed with a new Swift observation and archival NICER data. The total (energy- and phase-integrated) emission in the 2–8 keV energy range is linerarly polarized, at a ∼35% level. The phase-averaged polarization signal shows a marked increase with energy, ranging from ∼20% at 2–3 keV up to ∼80% at 6–8 keV, while the polarization angle remains constant. This indicates that radiation is mostly polarized in a single direction. The spectrum is well reproduced by a combination of either two thermal (blackbody) components or a blackbody and a power law. Both the polarization degree and angle also show a variation with the spin phase, and the former is almost anticorrelated with the source counts in the 2–8 and 2–4 keV bands. We discuss the possible implications and interpretations, based on a joint analysis of the spectral, polarization, and pulsation properties of the source. A scenario in which the surface temperature is not homogeneous, with a hotter cap covered by a gaseous atmosphere and a warmer region in a condensed state, provides a satisfactory description of both the phase- and energy-dependent spectro-polarimetric data. The (comparatively) small size of the two emitting regions, required to explain the observed pulsations, does not allow to reach a robust conclusion about the presence of vacuum birefringence effects.