Goods that provide positive externalities (i.e. merit goods) are underproduced because the benefits of the good have not been taken into account when constructing demand supply curves - essentially, the intersection of MPB (Marginal Private Benefit) and MPC (Marginal Private Cost) creates an equilibrium price excessively high and the MSB (Marginal Social Benefit) indicates that an equilibrium quantity should shift to the right
Conversely, goods that provide negative externalities (i.e. demerit goods) are overproduced because the detrimental nature of the good is not taken into account - the MSC is higher than the MPC, meaning that the current quantity of production is too high.