We consider systems confined to a $d$-dimensional slab of macroscopic lateral extension and finite thickness $L$ that undergo a continuous bulk phase transition in the limit $Ltoinfty$ and are describable by an O(n) symmetrical Hamiltonian. Periodic boundary conditions are applied across the slab. We study the effects of long-range pair interactions whose potential decays as $b x^{-(d+sigma)}$ as $xtoinfty$, with $2<sigma<4$ and $2<d+sigmaleq 6$, on the Casimir effect at and near the bulk critical temperature $T_{c,infty}$, for $2<d<4$. For the scaled reduced Casimir force per unit cross-sectional area, we obtain the form $L^{d} {mathcal F}_C/k_BT approx Xi_0(L/xi_infty) + g_omega L^{-omega}Xiomega(L/xi_infty) + g_sigma L^{-omega_sigm a} Xi_sigma(L xi_infty)$. The contribution $propto g_sigma$ decays for $T eq T_{c,infty}$ algebraically in $L$ rather than exponentially, and hence becomes dominant in an appropriate regime of temperatures and $L$. We derive exact results for spherical and Gaussian models which confirm these findings. In the case $d+sigma =6$, which includes that of nonretarded van-der-Waals interactions in $d=3$ dimensions, the power laws of the corrections to scaling $propto b$ of the spherical model are found to get modified by logarithms. Using general RG ideas, we show that these logarithmic singularities originate from the degeneracy $omega=omega_sigma=4-d$ that occurs for the spherical model when $d+sigma=6$, in conjunction with the $b$ dependence of $g_omega$.