Results are presented on a search for CP violation in the production and decay of top quark-antiquark pairs in the lepton+jets channel. The search is based on data from proton-proton collisions at s = 13 TeV, collected with the CMS detector, corresponding to an integrated luminosity of 138 fb−1. Possible CP violation effects are evaluated by measuring asymmetries in observables constructed from linearly independent four-momentum vectors of the final-state particles. The dimensionless chromoelectric dipole moment of the top quark obtained from the observed asymmetries is measured to be 0.04 ± 0.10 (stat) ± 0.07(syst), and the asymmetries exhibit no evidence for CP-violating effects, consistent with expectations from the standard model. [Figure not available: see fulltext.].