The dynamic process of a laser or particle beam propagating from vacuum into underdense plasma has been investigated theoretically. Our theoretical model combines a Lagrangian fluid model with the classic quasistatic wakefield theory. It is found that background electrons can be injected into wakefields because sharp vacuum-plasma transitions can reduce the injection threshold. The injection condition, injection threshold as well as the injection length can be given theoretically by our model and are compared with results from computer simulations. Moreover, electron beams of high qualities can be produced near the injection thresholds and the proposed scheme is promising in reducing the injection threshold and improving the beam qualities of plasma based accelerators.