The generation of radiation from free electrons passing a grating, known as Smith−Purcell radiation, finds various applications, including nondestructive beam diagnostics and tunable light sources, ranging from terahertz toward X-rays. So far, the gratings used for this purpose have been designed manually, based on human intuition and simple geometric shapes. Here we apply the computer-based technique of nanophotonic inverse design to build a 1400 nm Smith−Purcell radiator for subrelativistic 30 keV electrons. We demonstrate that the resulting silicon nanostructure radiates with a 3× higher efficiency and 2.2× higher overall power than previously used rectangular gratings. With better fabrication accuracy and for the same electron−structure distance, simulations suggest a superiority by a factor of 96 in peak efficiency. While increasing the efficiency is a key step needed for practical applications of free-electron radiators, inverse design also allows to shape the spectral and spatial emission in ways inaccessible with the human mind.