In this article, the piecewise-linear finite element method (FEM) is applied to approximate the solution of time-fractional diffusion equations on bounded convex domains. Standard energy arguments do not provide satisfactory results for such a problem due to the low regularity of its exact solution. Using a delicate energy analysis, a priori optimal error bounds in -, -norms, and a quasi-optimal bound in -norm are derived for the semidiscrete FEM for cases with smooth and nonsmooth initial data. The main tool of our analysis is based on a repeated use of an integral operator and use of a type of weights to take care of the singular behavior of the continuous solution at . The generalized Leibniz formula for fractional derivatives is found to play a key role in our analysis. Numerical experiments are presented to illustrate some of the theoretical results.