I think the U.S. basically won by the Soviets' "forfeiting". If USSR landed on the moon second but soon after, say, landed a man on Mars, and the U.S. unable to accomplish the feat, we would say the Soviets won.
After that the funding was heavily curtailed and redirected to other near-military projects like spy satellites.
The fact that the program itself was ruinously expensive for USSR (which was still less developed than US) and was burning precious R&D resources was also not insignificant.
Korolev by James Harford is a rather readable insight into what was going on inside the Soviet space program: https://www.goodreads.com/book/show/213301.Korolev