Let \la be a preprojective algebra of simply laced Dynkin type Δ. We study maximal rigid \la-modules, their endomorphism algebras and a mutation operation on these modules. This leads to a representation-theoretic construction of the cluster algebra structure on the ring \C[N] of polynomial functions on a maximal unipotent subgroup N of a complex Lie group of type Δ. As an application we obtain that all cluster monomials of \C[N] belong to the dual semicanonical basis.