Let Q be a finite quiver without oriented cycles, and let Λ be the associated preprojective algebra. To each terminal representation M of Q (these are certain preinjective representations), we attach a natural subcategory CM of mod(Λ). We show that CM is a Frobenius category,and that its stable category is a Calabi-Yau category of dimension 2. Then we develop a theory of mutations of maximal rigid objects of CM, analogous to the mutations of clusters in Fomin and Zelevinsky's theory of cluster algebras. We show that CM yields a categorification of a cluster algebra A(CM), which is not acyclic in general. We give a realization of A(CM) as a subalgebra of the graded dual of the enveloping algebra U(\n), where \n is a maximal nilpotent subalgebra of the symmetric Kac-Moody Lie algebra \g associated to the quiver Q. Let S∗ be the dual of Lusztig's semicanonical basis S of U(\n). We show that all cluster monomials of A(CM) belong to S∗, and that S∗∩A(CM) is a basis of A(CM). Next, we prove that A(CM) is naturally isomorphic to the coordinate ring of the finite-dimensional unipotent subgroup N(w) of the Kac-Moody group G attached to \g. Here w = w(M) is the adaptable element of the Weyl group of \g which we associate to each terminal representation M of Q. Moreover, we show that the cluster algebra obtained from A(CM) by formally inverting the generators of the coefficient ring is isomorphic to the coordinate ring of the unipotent cell Nw:=N∩(B−wB−) of G. We obtain a corresponding dual semicanonical basis of this coorindate ring.