Using first-principles methods based on density-functional theory, we investigate the spin relaxation in W(001) ultrathin films. Within the framework of the Elliott-Yafet theory, we calculate the spin mixing of the Bloch states and we explicitly consider spin-flip scattering off self-adatoms. At small film thicknesses, we find an oscillatory behavior of the spin-mixing parameter and relaxation rate as a function of the film thickness, which we trace back to surface-state properties. We also analyze the Rashba effect experienced by the surface states and discuss its influence on the spin relaxation. Finally, we calculate the anisotropy of the spin-relaxation rate with respect to the polarization direction of the excited spin population relative to the crystallographic axes of the film. We find that the spin-relaxation rate can increase by as much as 27% when the spin polarization is directed out of plane, compared to the case when it is in plane. Our calculations are based on the multiple-scattering formalism of the Korringa-Kohn-Rostoker Green-function method.