Let n ≥ 1, e ≥ 1, k ≥ 2 and c be integers. An integer u is called a unit in the ring Zn of residue classes modulo n if gcd(u, n) = 1. A unit u is called an exceptional unit in the ring Zn if gcd(1 − u, n) = 1. We denote by N k,c,e (n) the number of solutions (x 1 , ..., x k ) of the congruence x e 1 +...+x e k ≡ c (mod n) with all x i being exceptional units in the ring Zn. In 2017, Mollahajiaghaei presented a formula for the number of solutions (x 1 , ..., x k ) of the congruence x 2 1 + ... + x 2 k ≡ c (mod n) with all x i being the units in the ring Zn. Meanwhile, Yang and Zhao gave an exact formula for N k,c,1 (n). In this paper, by using Hensel's lemma, exponential sums and quadratic Gauss sums, we derive an explicit formula for the number N k,c,2 (n). Our result extends Mollahajiaghaei's theorem and that of Yang and Zhao.