Much like the early US space program, the Soviet space program grew out of the development of intercontinental ballistic missiles (ICBM).
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.