We formulate a time-dependent density-functional theory ͑TDDFT͒ in terms of the density matrix to study ultrafast phenomena in semiconductor structures. A system of equations for the density-matrix components, which is equivalent to the time-dependent Kohn-Sham equation, is derived. From this, we obtain a TDDFT version of the semiconductor Bloch equations, where the electronic many-body effects are taken into account, in principle, exactly. As an example, we study the optical response of a three-dimensional two-band insulator to an external short-time pulsed laser field. We show that the optical absorption spectrum acquires excitonic features when the exchange-correlation potential contains a 1 / q 2 Coulomb singularity. A qualitative comparison of the TDDFT optical absorption spectra with the corresponding results obtained within the Hartree-Fock approximation is made.