Higher order interactions (HOIs) have been suggested to stabilize diverse ecological communities. However, their role in maintaining species coexistence from the perspective of modern coexistence theory is not known. Here, using generalized Lotka-Volterra model, we derive a general rule for species coexistence modulated by HOIs. We show that where pairwise species interactions fail to promote species coexistence in regions of extreme fitness differences, negative HOIs that intensify pairwise competition, however, can promote coexistence provided that HOIs strengthen intraspecific competition more than interspecific competition. In contrast, positive HOIs that alleviate pairwise competition can stabilize coexistence across a wide range of fitness differences, irrespective of differences in strength of inter- and intraspecific competition. In addition, we extend our three-species analytical result to multispecies communities and show, using simulations, that multispecies coexistence is possible provided that strength of negative intraspecific HOIs is higher than interspecific HOIs. Our work sheds light on the underlying mechanisms through which HOIs can maintain species diversity.