This paper gives an algorithm to factor a polynomial f (in one variable) over rings like Z=rZ for r 2 Z or F q [y]=rF q [y] for r 2 F q [y]. The Chinese Remainder Theorem reduces our problem to the case where r is a prime power. Then factorization is not unique, but if r does not divide the discriminant of f , our (probabilistic) algorithm produces a description of all (possibly exponentially many) factorizations into irreducible factors in polynomial time. If r divides the discriminant, we only know how to factor by exhaustive search, in exponential time.