For the partition function p(n), Ramanujan proved the striking identities \(\begin{aligned} \begin{aligned} \mathcal {P}_5(q):=\sum _{n\ge 0} p(5n+4)q^n&=5\prod _{n\ge 1} \frac{\left( q^5;q^5\right) _{\infty }^5}{(q;q)_{\infty }^6},\\ \mathcal {P}_{7}(q):=\sum _{n\ge 0} p(7n+5)q^n&=7\prod _{n\ge 1}\frac{\left( q^7;q^7\right) _{\infty }^3}{(q;q)_{\infty }^4}+49q \prod _{n\ge 1}\frac{\left( q^7;q^7\right) _{\infty }^7}{(q;q)_{\infty }^8}, \end{aligned} \end{aligned}\) where \((q;q)_{\infty }:=\prod _{n\ge 1}(1-q^n).\) As these identities imply his celebrated congruences modulo 5 and 7, it is natural to seek, for primes \(\ell \ge 5,\) closed form expressions of the power series \( \mathcal {P}_{\ell }(q):=\sum _{n\ge 0} p(\ell n-\delta _{\ell })q^n\pmod {\ell }, \) where \(\delta _{\ell }:=\frac{\ell ^2-1}{24}.\) In this paper, we prove that \( \mathcal {P}_{\ell }(q)\equiv c_{\ell } \dfrac{\mathcal {T}_{\ell }(q)}{\left( q^\ell ; q^\ell \right) _\infty } \pmod {\ell }, \) where \(c_{\ell }\in \mathbb Z\) is explicit and \({\mathcal {T}}_{\ell }(q)\) is the generating function for the Hecke traces of \(\ell \) -ramified values of special Dirichlet series for weight \(\ell -1\) cusp forms on \(\textrm{SL}_2(\mathbb Z)\) . This is a new proof of Ramanujan’s congruences modulo 5, 7, and 11, as there are no nontrivial cusp forms of weight 4, 6, and 10.