An imperative condition for the functioning of a power-grid network is that its power generators remain synchronized. Disturbances can prompt desynchronization, which is a process that has been involved in large power outages. Here we derive a condition under which the desired synchronous state of a power grid is stable, and use this condition to identify tunable parameters of the generators that are determinants of spontaneous synchronization. Our analysis gives rise to an approach to specify parameter assignments that can enhance synchronization of any given network, which we demonstrate for a selection of both test systems and real power grids. Because our results concern spontaneous synchronization, they are relevant both for reducing dependence on conventional control devices, thus offering an additional layer of protection given that most power outages involve equipment or operational errors, and for contributing to the development of smart grids that can recover from failures in real time.