Nonthermal acceleration of relativistic electrons due to the wakefield induced by an intense light pulse is investigated. The spectra of the cosmic rays are well represented by power-law. Wakefield acceleration has been considered as a candidate for the origins of cosmic rays. The wakefield can be excited by an intense laser pulse as large-amplitude precursor waves in collisionless shocks in the universe. National Central University (NCU) 100-TW laser facility in Taiwan is able to provide high-repetition rate and short intense laser. To experimentally study the wakefield acceleration for the spectrum of the cosmic rays, particle-in-cell simulations are performed to calculate the energy distribution functions of electrons in fixed laser conditions with various plasma densities. The transitions of wakefields from coherent to inherent are observed as the plasma density increases. The distribution functions indicate that the smooth nonthermal power-law spectra with an index of −2 appear when the incoherent wakefields are excited. In contrast, the mono-peak appear in the spectra when the coherent wakefields are excited. The incoherent wakefields yielding the power-law spectra imply the stochastic accelerating of electrons. To explain the universal nonthermal power-law spectra with an index of −2, we described and extended the stochastic acceleration model based on Fokker–Planck equation by assuming the transition rate as an exponential function.