We use a recently improved density-matrix expansion to calculate the nuclear energy density functional in the framework of in-medium chiral perturbation theory. Our calculation treats systematically the effects from 1 π-exchange, iterated 1 π-exchange, and irreducible 2 π-exchange with intermediate Δ-isobar excitations, including Pauli-blocking corrections up to three-loop order. We find that the effective nucleon mass M ∗ ( ρ ) entering the energy density functional is identical to the one of Fermi-liquid theory when employing the improved density-matrix expansion. The strength F ∇ ( ρ ) of the ( ∇ → ρ ) 2 surface-term as provided by the pion-exchange dynamics is in good agreement with that of phenomenological Skyrme forces in the density region ρ 0 / 2 < ρ < ρ 0 . The spin–orbit coupling strength F so ( ρ ) receives contributions from iterated 1 π-exchange (of the “wrong sign”) and from three-nucleon interactions mediated by 2 π-exchange with virtual Δ-excitation (of the “correct sign”). In the region around ρ 0 / 2 ≃ 0.08 fm − 3 where the spin–orbit interaction in nuclei gains most of its weight these two components tend to cancel, thus leaving all room for the short-range spin–orbit interaction. The strength function F J ( ρ ) multiplying the square of the spin–orbit density comes out much larger than in phenomenological Skyrme forces and it has a pronounced density dependence.