In the ocean most likely.
How the first transition was made between non-living organic molecules and the earliest living things is not really known, but the process may not have been random and was certainly not altogether random even if it included random components.
So, if it wasn't random or spontaneous, or designed, then what was it?
I obviously can't answer that in detail, because it's not known, but here's how it MIGHT have happened, in general terms.
Start with a very hot, lifeless planet, with more or less the current chemical composition (as far as elements are concerned -- compounds would be different because of temperature differences and because there was no life).
Over time, it cools enough that water vapor precipitates and forms the oceans. Water dissolves certain chemicals and, with energy provided by sunlight and perhaps some other sources, chemical reactions involving nitrogen, carbon, and hydrogen compounds form "organic" compounds. (Speaking chemically -- obviously they're not "organic" in terms of source, that is, not from living things. At this point there are no living things.)
An important step here is the formation of amino acids. It's been proven in the laboratory that these compounds can form from non-living processes. Another crucial step, and this has also been laboratory demonstrated, is the formation of nucleotides, which are the building-block molecules of nucleic acids, as amino acids are of proteins. So we can easily understand how both amino acids and nucleotides come to be in the absence of actual life; these are precursor chemicals to life.
The most popular hypothesis these days for how life began, and note that this part has definitely not been proven, it's just a speculative idea to play with and try to find evidence for or against, involves RNA providing a reproductive-information function rather than DNA which does the job in all living things today. (Or all that I know about. RNA still has an important function in transmitting DNA instructions to proteins) The emergence of a molecule capable of transmitting information and so of replicating itself, which RNA can do, would fit the main part of the definition of life. Once that happened, it would begin replicating, and any mutations that occurred would begin the process of evolution, along with natural selection to guide the process.
Exactly how this occurred is not known, but it would not necessarily have been a "random" process at any point before the occurrence of the first mutation, except maybe in terms of precisely what characteristics the first RNA molecules would have exhibited. (It's likely there would have been more than one.) And even if that was itself random, it would have built on a whole sequence of events that were not, creating the circumstances in which life could begin.