A new algorithm is presented to discriminate reconstructed hadronic decays of tau leptons ($\tau_\mathrm{h}$) that originate from genuine tau leptons in the CMS detector against $\tau_\mathrm{h}$ candidates that originate from quark or gluon jets, electrons, or muons. The algorithm inputs information from all reconstructed particles in the vicinity of a $\tau_\mathrm{h}$ candidate and employs a deep neural network with convolutional layers to efficiently process the inputs. This algorithm leads to a significantly improved performance compared with the previously used one. For example, the efficiency for a genuine $\tau_\mathrm{h}$ to pass the discriminator against jets increases by 10-30% for a given efficiency for quark and gluon jets. Furthermore, a more efficient $\tau_\mathrm{h}$ reconstruction is introduced that incorporates additional hadronic decay modes. The superior performance of the new algorithm to discriminate against jets, electrons, and muons and the improved $\tau_\mathrm{h}$ reconstruction method are validated with LHC proton-proton collision data at $\sqrt{s} =$ 13 TeV.