We give a general construction of correlation functions in rational conformal field theory on a possibly nonorientable surface with boundary in terms of three-dimensional topological field theory. The construction applies to any modular category in the sense of Turaev. It is proved that these correlation functions obey modular invariance and factorization rules. Structure constants are calculated and expressed in terms of the data of the modular category.