The stellar initial mass function (IMF) describes the distribution of stellar mass formed in star formation episodes, shaping galaxies' properties. It's a fundamental distribution in astronomy. Whether the IMF is constant or variable across environments is debated, despite theoretical and observational efforts. Past measurements of the IMF in Galactic stellar populations were limited by small star counts, causing uncertainties. We studied ~100,000 spectroscopically observed M-dwarf stars in the 100–300 parsec solar neighborhood from LAMOST survey. We find evidence of a variable IMF that depends on metallicity and stellar age. Low-mass star proportions increase with metallicity. This variable IMF impacts models of star formation, Galactic chemical-enrichment, galaxy mass estimation, and planet-formation efficiency.