The Turkey international joined Real last year after helping Borussia Dortmund win the 2011 Bundesliga title but found opportunities limited because of injury and the form of Mesut Ozil.
Real boss Jose Mourinho was keen for Sahin to go to England to restart his career and Liverpool have swooped after interest from Arsenal cooled.
"The 23-year-old will now undergo a medical on Merseyside," a Liverpool statement said.
Sahin's departure from the Bernabeu is another indication that Tottenham Hotspur's creative midfielder Luka Modric could head to Real, while the future of Kaka remains uncertain.
Liverpool boss Brendan Rodgers has hinted that Sahin would be a major first-team player at Anfield despite playing in a similar role to captain Steven Gerrard, who may now be asked to operate wide or as a holding midfielder.
With Sahin's medical still to be completed, the 31-cap player will not be available for Sunday's home league game against champions Manchester City.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.