  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, {\it a priori} optimal error bounds in
$L^2(\Omega)$-, $H^1(\Omega)$-norms, and a quasi-optimal bound in
$L^{\infty}(\Omega)$-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 $t^m$ type of weights to take
care of the singular behavior of the continuous solution at $t=0.$ 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.
