A function on an algebra is congruence preserving if, for any congruence, it maps congruent elements to congruent elements. We show that, on a free monoid generated by at least 3 letters, a function from the free monoid into itself is congruence preserving if and only if it is of the form x → w 0 xw 1 · · · w n−1 xw n for some finite sequence of words w 0 , . . . , w n . We generalize this result to functions of arbitrary arity. This shows that a free monoid with at least three generators is a (noncommutative) affine complete algebra. Up to our knowledge, it is the first (nontrivial) case of a noncommutative affine complete algebra.