Mozart composed his first pieces at age 5 (K. 1–5, small keyboard pieces) and his first opera, Apollo et Hyacinthus, at age 11 (1767, K. 38). He died at 35—so yes, he completed a vast output well before 40.
The "age 5" compositions (K. 1a–1f, 2, 3, 4, 5) were likely written down by Leopold from Wolfgang's improvisations; by 6 he was notating himself. The trajectory: prodigy → touring virtuoso → mature master — all before most composers finish conservatory.