Fitting percolation into the conformal field theory framework requires showing that connection probabilities have a conformally invariant scaling limit. For critical site percolation on the triangular lattice, we prove that the probability that n vertices belong to the same open cluster has a well-defined scaling limit for every n ≥ 2. Moreover, the limiting functions P n (x 1 , . . . , x n ) transform covariantly under Möbius transformations of the plane as well as under local conformal maps, i.e., they behave like correlation functions of primary operators in conformal field theory. In particular, they are invariant under translations, rotations and inversions, and, for some constants C 2 and C 3 . Another immediate consequence is that the ratio P 3 (x 1 , x 2 , x 3 )/ P 2 (x 1 , x 2 )P 2 (x 1 , x 3 )P 2 (x 2 , x 3 ) is independent of x 1 , x 2 , x 3 , which confirms a prediction of the physics literature.We also define a site-diluted spin model whose n-point correlation functions C n can be expressed in terms of percolation connection probabilities and, as a consequence, have a well-defined scaling limit with the same properties as the functions P n . In particular, C 2 (x 1 , x 2 ) = P 2 (x 1 , x 2 ). We prove that the magnetization field associated with this spin model has a well-defined scaling limit in an appropriate space of distributions. The limiting field transforms covariantly under Möbius transformations with exponent (scaling dimension) 5/48. A heuristic analysis of the four-point function of the magnetization field reveals the presence of an additional conformal field of scaling dimension 5/4, which counts the number of percolation four-arm events and can be identified with the so-called "four-leg operator" of conformal field theory.The proofs make essential use of the fact that, in the scaling limit, the collections of percolation interfaces and of counting measures of open clusters converge to a conformal loop ensemble and a conformal measure ensemble, respectively.