We formulated a mathematical model to study the evolution of biodiversity. Our model describes a collection of sites and incorporates a simple but explicit description of the competitive processes within a site. In our model the characteristics of component species evolve towards an evolutionarily stable state and in this way an evolutionarily stable assemblage of species is formed. We show that the number of species in these assemblages matches two well-documented patterns in biodiversity: the increase in the number of species towards the equator and the dependence of the number of species on the productivity of habitat: the average number of species rises to a maximum and then falls when plotted against increasing productivity of that habitat. Our results show that population dynamical and evolutionary processes can underlie patterns in biodiversity.