Ultrashort electron beams with a narrow energy spread, high charge, and low jitter are essential for resolving phase transitions in metals, semiconductors, and molecular crystals. These accelerated beams, produced by phototriggered electron guns, are also injected into accelerators for x-ray light sources. The achievable resolution of these time-resolved electron diffraction or x-ray experiments has been hindered by surface field and timing jitter limitations in conventional RF guns, which thus far are <200 MV/m and >96 fs, respectively. A gun driven by optically generated single-cycle terahertz (THz) pulses provides a practical solution for enabling not only GV/m surface fields but also absolute timing stability, since the pulses are generated by the same laser as the phototrigger. Here, we demonstrate an all-optical THz gun yielding a peak electron energy approaching 1 keV, accelerated by >300 MV/m THz fields in a micrometer-scale waveguide structure. We also achieve quasi-monoenergetic, sub-kiloelectron volt bunches with 32 fC of charge, which can already be used for time-resolved low-energy electron diffraction. Such ultracompact, easy-to-implement guns—driven by intrinsically synchronized THz pulses that are pumped by an amplified arm of the already-present photoinjector laser—provide a new tool with the potential to transform accelerator-based science.