When a system crosses a second-order phase transition on a finite timescale, spontaneous symmetry breaking can cause the development of domains with independent order parameters, which then grow and approach each other creating boundary defects. This is known as Kibble-Zurek mechanism. Originally introduced in cosmology, it applies both to classical and quantum phase transitions, in a wide variety of physical systems. Here we report on the spontaneous creation of solitons in Bose-Einstein condensates via the Kibble-Zurek mechanism. We measure the power-law dependence of defects number with the quench time, and provide a check of the Kibble-Zurek scaling with the sonic horizon. These results provide a promising test bed for the determination of critical exponents in Bose-Einstein condensates.The Kibble-Zurek mechanism (KZM) describes the spontaneous formation of defects in systems that cross a second-order phase transition at finite rate [1][2][3][4]. The mechanism was first proposed in the context of cosmology to explain how during the expansion of the early Universe the rapid cooling below a critical temperature induced a cosmological phase transition resulting in the formation domain structures. In fact, the KZM is ubiquitous in nature and regards both classical and quantum phase transitions [5,6]. Experimental evidences have been observed in superfluid 4 He [7,8] and 3 He [9,10], in superconducting films [11] and rings [12][13][14][15][16] and in ion chains [17,18]. Bose-Einstein condensation in trapped cold gases has been considered as an ideal platform for the KZM [19][20][21][22][23]; the system is extremely clean and controllable and particularly suitable for the investigation of interesting effects arising from the spatial inhomogeneities induced by the confinement. Quantized vortices produced in a pancake-shaped condensate by a fast quench across the transition temperature have been already observed [24], but their limited statistics prevented the test of the KZM scaling. The KZM has been studied across the quantum superfluid to Mott insulator transition with atomic gases trapped in optical lattices [25]. Here we report on the observation of solitons resulting from phase defects of the order parameter, spontaneously created in an elongated Bose-Einstein condensate (BEC) of sodium atoms. We show that the number of solitons in the final condensate grows according to a power-law as a function of the rate at which the BEC transition is crossed, consistent with the expectations of the KZM, and provide the first check of the KZM scaling with the sonic horizon. We support our observations by comparing the estimated speed of the transition front in the gas to the speed of the sonic causal horizon, showing that solitons are produced in a regime of inhomogeneous Kibble-Zurek mechanism (IKZM) [21]. Our measurements can open the way to the determination of the critical exponents of the BEC transition in trapped gases, for which so far little information is available [26].The KZM predicts the formation of independen...