Answer:
Before the Bay of Pigs invasion, Castro was already strenghtening ties with the Soviet Union, but it was after this even that the ties became closer.
Castro was faced with the direct threat of an US invasion and overthrow, therefore, he sought military help from the Soviet Union. Castro himself asked then-leader of the Soviet Union, Nikita Khrushchev, to place nuclear missiles in Cuban soil in order to deter a possible invasion.
Fortunately, the outcome of the crisis was satisfactory, but this chain of events led to what could have been an event of mass destruction and human exctintion had the missiles been used.