Systems with an O(n) symmetrical Hamiltonian are considered in a d-dimensional slab geometry of macroscopic lateral extension and finite thickness L that undergo a continuous bulk phase transition in the limit L→∞. The effective forces induced by thermal fluctuations at and above the bulk critical temperature Tc,∞ (thermodynamic Casimir effect) are investigated below the upper critical dimension d∗=4 by means of field-theoretic renormalization group methods for the case of periodic and special-special boundary conditions, where the latter correspond to the critical enhancement of the surface interactions on both boundary planes. As shown previously [\textit{Europhys. Lett.} \textbf{75}, 241 (2006)], the zero modes that are present in Landau theory at Tc,∞ make conventional RG-improved perturbation theory in 4−ϵ dimensions ill-defined. The revised expansion introduced there is utilized to compute the scaling functions of the excess free energy and the Casimir force for temperatures T\geqTc,∞ as functions of L≡L/ξ∞, where ξ∞ is the bulk correlation length. Scaling functions of the L-dependent residual free energy per area are obtained whose L→0 limits are in conformity with previous results for the Casimir amplitudes ΔC to O(ϵ3/2) and display a more reasonable small-L behavior inasmuch as they approach the critical value ΔC monotonically as L→0.