The process of Natural Transformation (Lorenz and Wackernagel 1994) has a very huge importance in evolution of prokaryotes. Definition quoting from (Stewart and Carlson 1986)
Natural transformation is part of the normal physiology of the cell.
It is the only form of bacterial genetic exchange whose functions are
encoded on the chromosome, and competence is a heritable trait,
subject to selective pressure.
This is almost similar to our daily use artificial transformation. You need some chemical like $CaCl_2$ to cell permiabalized, some chelating agents like EDTA and DNA material. You can imagine naturally occurring cell encountering such conditions, like decrease in temperature in presence of certain chemicals and proteins.
This concept of one cell externalising, and another internalising DNA got stronger when researchers observed free DNA in culture media (Catlin 1959, Sinha and Iyer 1971).
The Creation of eDNA
The release of eDNA (extracellular DNA) can occur via spontaneous excretion or autolytic action.
There are known mechanisms for the release eDNA like formation of blebs (Dorward and Garon 1990). This extracellular DNA production is affected by many physiochemical factors than biotic (Paul and David 1989). There are many in detailed reports which shows such DNA can be passed through cell wall without any cell damage (Hara and Ueda 1981). Half life of such eDNA in various environment is reported in following table from (Lorenz and Wackernagel 1994)
Now there are even more novel ways of production of extracellular DNA like in Neisseria gonorrhoeae secretion of chromosomal DNA occure via new type IV secretion system (Hamilton et al 2005). Not just experiments, mathematical models also shows novel role of such process in gene-level selection (Draghi and Turner 2006). I haven't touched upon uptake of these DNA, which itself has lot of literature and unique mechanisms like this.