  Using effective field theory methods, we compute in detail the Lagrangian for
the conservative dynamics of compact binary systems, for spinless constituents
and in the gravitationally bound case, in massless scalar-tensor (ST) and
Einstein-scalar-Gauss-Bonnet gravity (EsGB) to the second post-Newtonian (2PN)
order. We employ the Kaluza-Klein parametrization of the metric, and
demonstrate that, also in this case, a significant reduction in the number of
diagrams is achieved. Still, to the 2PN accuracy, an additional 39 diagrams
involving scalar interactions must be added to the pure general relativistic
result. Diagrams involving the Gauss-Bonnet term at the formal 1PN order are
computed and shown to scale as a 3PN correction when observational constraints
are taken into account. We also investigate at which order the additional
$\mathcal{O}(G^3)$ topologies contribute. Finally, the results derived in this
paper provide an essential step toward the correct derivation of the
conservative dynamics at the 3PN level in ST and EsGB theories.
