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.