We compute the cohomology of modules over the algebra of twisted chiral differential operators over the flag manifold. This is applied to (1) finding the character of G-integrable irreducible highest weight modules over the affine Lie algebra at the critical level, and (2) computing a certain elliptic genus of the flag manifold. The main tool is a result that interprets the Drinfeld-Sokolov reduction as a derived functor.