The roles of species richness, resource use, and resource availability are central to many hypotheses explaining the diversity–invasion phenomenon but are generally not investigated together. Here, we created a large diversity gradient of soil microbial communities by either assembling communities of pure bacterial strains or removing the diversity of a natural soil. Using data on the resource-use capacities of the soil communities and an invader that were gathered from 71 carbon sources, we quantified the niches available to both constituents by using the metrics community niche and remaining niche available to the invader. A strong positive relationship between species richness and community niche across both experiments indicated the presence of resource complementarity. Moreover, community niche and the remaining niche available to the invader predicted invader abundance well. This suggested that increased competition in communities of higher diversity limits community invasibility and underscored the importance of resource availability as a key mechanism through which diversity hinders invasions. As a proof of principle, we subjected selected invaded communities to a resource pulse, which progressively uncoupled the link between soil microbial diversity and invasion and allowed the invader to rebound after nearly being eliminated in some communities. Our results thus show that (1) resource competition suppresses invasion, (2) biodiversity increases resource competition and decreases invasion through niche preemption, and (3) resource pulses that cannot be fully used, even by diverse communities, are favorable to invasion.