The process by which the kidneys remove excess or undesired substances from the blood and excrete them in the urine.