Trees are self-similar branching structures, hierarchically organized with longer and thicker branches near the roots. With a mechanically-based numerical model, we show how self-similarity can emerge through natural selection. In this model, trees grow into fractal structures to promote efficient photosynthesis in a competing environment. In addition, branch diameters increase in response to wind-induced loads. Remarkably, the virtual tree species emerging from this model have the same self-similar properties as those measured on conifers and angiosperms.