We calculate the three-loop soft function for the production of an electroweak boson (Higgs, γ, W±, Z) with large transverse momentum at a hadron collider. It is the first time a soft function for a three-parton process is computed at next-to-next-to-next-to-leading order (N3LO). As a technical novelty, we perform the calculation in terms of forward-scattering-type loop diagrams rather than evaluating phase space integrals. Our three-loop result contains color-tripole contributions and explicitly confirms predictions on the universal infrared structure of QCD scattering amplitudes with three massless parton legs. The soft function is a central ingredient in the factorized cross section for electroweak boson production near the kinematic endpoint (threshold), where the invariant mass of the recoiling hadronic radiation is small compared to its transverse momentum. Our result is required for predictions of the near-threshold cross sections at N3LO and for the resummation of threshold logarithms at primed next-to-next-to-next-to-leading logarithmic (N3LL′) accuracy.