  We introduce a class of quantum integrable systems generalizing the Gaudin
model. The corresponding algebras of quantum Hamiltonians are obtained as
quotients of the center of the enveloping algebra of an affine Kac-Moody
algebra at the critical level, extending the construction of higher Gaudin
Hamiltonians from hep-th/9402022 to the case of non-highest weight
representations of affine algebras. We show that these algebras are isomorphic
to algebras of functions on the spaces of opers on P^1 with regular as well as
irregular singularities at finitely many points. We construct eigenvectors of
these Hamiltonians, using Wakimoto modules of critical level, and show that
their spectra on finite-dimensional representations are given by opers with
trivial monodromy. We also comment on the connection between the generalized
Gaudin models and the geometric Langlands correspondence with ramification.
