The adsorption of N2 and CO on Ru(001) has been investigated through density functional theory calculations for the ordered (sqrt(3) x sqrt(3))R30 structure. Calculated vibrational frequencies, geometry and adsorption energies of the two systems agree well with experiment. We explain the large difference in adsorption energy for the two molecules, using a simple model involving the coupling between the Ru-d states and the molecular 2-pi and 5-sigma states.