We demonstrate a new mechanism for coherent terahertz radiation. In a dielectric waveguide grating structure, the waveguide mode can by excited by moving electrons, and then resonantly couples with the diffraction waves by the grating to form coherent THz radiation. The resonance greatly narrows the linewidth and enhances the radiation power density at the peak frequency. The radiation frequency can be widely tuned by varying the beam energy or the waveguide thickness. This mechanism could provide a promising way for the development of room temperature, narrow linewidth, high powered, and coherent terahertz radiation source covering the entire terahertz band.