Let R be a prime ring and n > 1 be a fixed positive integer. If g is a nonzero generalized derivation of R such that g(x)n=g(x) for all x ∈ R, then R is commutative except when R is a subring of the 2 × 2 matrix ring over a field. Moreover, we generalize the result to the case g(f(xi))n = g(f(xi)) for all x1, x2, ..., xt∈ R, where f(Xi) is a multilinear polynomial.