A search is presented for additional scalar (H) or pseudoscalar (A) Higgs bosons decaying to a top quark pair in proton-proton collisions at a center-of-mass energy of 13 TeV. The data set analyzed corresponds to an integrated luminosity of 35.9 fb−1 collected by the CMS experiment at the LHC. Final states with one or two charged leptons are considered. The invariant mass of the reconstructed top quark pair system and variables that are sensitive to the spin of the particles decaying into the top quark pair are used to search for signatures of the H or A bosons. The interference with the standard model top quark pair background is taken into account. A moderate signal-like deviation compatible with an A boson with a mass of 400 GeV is observed with a global significance of 1.9 standard deviations. New stringent constraints are reported on the strength of the coupling of the hypothetical bosons to the top quark, with the mass of the bosons ranging from 400 to 750 GeV and their total relative width from 0.5 to 25%. The results of the search are also interpreted in a minimal supersymmetric standard model scenario. Values of mA from 400 to 700 GeV are probed, and a region with values of tan β below 1.0 to 1.5, depending on mA, is excluded at 95% confidence level. [Figure not available: see fulltext.].