The Soviet attempt to reach the moon before the US was a marred by conflict with military priorities and conflict between designers over rockets, mission design and engines. Formal approval for a realistic lunar-dedicated super-heavy N1 booster was only given in 1964, 4 years after the US began the Apollo-Saturn project. The untimely death of the chief designer, Sergei Korolev, in 1966, likely derailed the N1 project entirely. Subsequently the N1 suffered a series of catastrophic launch failures. The project was suspended in 1974 and officially cancelled in 1976, dooming any Soviet moon landing.
When the Soviets became aware of the US intention to land a man on the moon (at Kennedy's May 1961 announcement) Sergei Korolev, the chief designer behind both the military and civilian Soviet rocket program, sought to develop a super-heavy N1 entirely for a manned lunar mission. However, the N1 was poorly funded for many years as the military considered ICBMs were the priority.
Much like the early US space program, the Soviet space program grew out of the development of intercontinental ballistic missiles (ICBM). Soyuz itself was part of the R-7 rocket family, primarily intended as an ICBM. The first test launch of the family was the ICBM R-7 Semyorka on 15 May 1957. The "civilian" Sputnik 1 satellite - the very first satellite - was launched using an R-7 variant, the Soyuz, in October 1957. The R7 Semyorka would later carry a 3-5 Mt warhead, becoming the USSR's first operational ICBM in September 1960, about a year after the SM-65 Atlas.
An early proposal was to use multiple Soyuz launches to assemble a lunar "package" in Earth orbit. Complex, expensive and impractical, this was ultimately abandoned.
Another designer, Vladimir Chelomey, proposed a mission based on multiple UR-200 ICBMs and later a single UR-500 booster. The UR-500 was designed to launch a single 100 Mt warhead. It later became the very successful, and largely civilian, Proton rocket family. The Proton would allow a lunar mission with a single Cosmonaut, but only on a lunar flyby, not a landing. It was hoped this would be achieved prior to the US's first lunar (non-landing) mission, Apollo 10. The USSR rocket forces were also reluctant to divert resources to Chelomey's proposed mission.
Meanwhile, Korolev sought to draw funding for his N1 design by trying to sell it as an ICBM for the Tsar Bomba, the largest nuclear bomb of all time. But the military saw a Soviet lunar mission as an expensive distraction, that could not be justified unless it was a minor modification to its ICBM program.
Korolev also clashed fiercely with Valentin Glushko, who had a monopoly on Soviet rocket engine design and production. Glushko's designs used (toxic) hypergolic bipropellants for his ICBMs, which Korolev considered too risky for a manned mission. Glushko refused outright to design an engine using Korolev's preferred LOX/kerosene fuel.
Korolev ultimately sought the help of Nikolai Kuznetsov, a jet engine designer - with limited rocker design experience - to build the NK-15 LOX/kerosene fueled rocket motors. The NK-15 was much smaller than the Saturn V F-1 engines. As a consequence 30 NK-15s were required for the N1 booster.
Much like the SpaceX Super Heavy the first stage had a large number of smaller engines (30 vs 33 for the Super). Like the Super Heavy the Soviets were using a new fuel for the first time (RP-1/LOX, like the Saturn V Stage 1, methane/LOX for the Super). And much like the Super Heavy and the SpaceX Starship, the rushed development resulted in the N1 suffering multiple early failures.
During testing, which began in February 1969, 3 years after Korolev's death, there were 4 consecutive failures after launch, one of which was a spectacular explosion. At the time of the last test launch failure in November 1972, Apollo 16 had already landed on the moon. The final of the six US lunar landing missions, Apollo 17, touched down on the moon in December 1972. Interestingly, Apollo used a lunar orbit rendezvous mission, the same design intended by Korolev for his N1.
After Korolev's death and the N1 launch failures, Glushko, who by then had been appointed manager of the program, suspended the N1 development. He ultimately cancelled it in 1976, and then, teaming up with other designers in that year, commenced the development of the successful Energia super-heavy booster. However, the propaganda and national pride incentive for a Soviet lunar mission had long been lost.
Korolev was the father of the Soviet space program. Under his leadership the Soviets achieved many space milestones prior to the US, but given the N1 development was started so late, initially underfunded, rushed and then mired in conflict between designers (Korolev vs Glushko and Korolev vs Chelomey), it's unlikely - even if Korolev lived - that the Soviets would have got to the Moon first. It was too late to compete with the US Apollo program.
https://en.wikipedia.org/wiki/N1_(rocket)