Existence and stability of periodic solutions for second-order semilinear differential equations with a singular nonlinearity