The 25-year-old midfielder has agreed a four-year contract at Loftus Road after making 60 appearances for Los Blancos.
In a statement released by the Barclays Premier League club, R's boss Mark Hughes said: "He is a great player, first and foremost. You don't play at a club like Real Madrid if you're not."
Hughes added: "He has been there from the age of nine, so this has been a huge decision for him. He is very well regarded there and for him to leave a club of that stature to come to us shows the belief he has in what we are trying to do.
"He has got great energy and is technically very gifted, as you would expect from a Real Madrid player.
"He is very comfortable on the ball and is an all-round excellent midfielder, which we will benefit from."
QPR are also in talks with Marseille over Cameroon defensive midfielder Stephane M’Bia, although that move is dependent on Barton going the other way.
Barton is surplus to requirements after being slapped with a 12-match ban for his dismissal against Manchester City at the end of last season.
M’Bia, 26, had announced that he was set to join QPR, but any deal for him is dependent on the completion of the Barton transfer, Marseille said.
“Right now there is no agreement,” a Marseille official told AFP. “M’Bia was possibly getting ahead of himself. He did not play (in the Europa League match with Sheriff Tiraspol) because he is in transfer negotiations.”
M'Bia had said he was set to join QPR, despite interest from Turkish side Fenerbahce.
"Marseille is still in my heart," he said. "I won my first titles here. I have chosen Queens Park Rangers despite a last-minute bid from Fenerbahce. It's a new challenge to enjoy. I always aim as high as possible.
"I am excited but calm over this move. I will discover another world."
Barton, meanwhile, was filmed undergoing the second part of his medical at Marseille ahead of a proposed move, which would either be a season-long loan or a free transfer.
The controversial midfielder, 29, has expressed his desire to restart his career in France.
The Liverpool-born player has unquestionable ability but a problematic temperament. Off-field problems – which resulted in a short prison sentence in 2008 – have been reduced after he addressed an alcohol problem, but he is still prone to lashing out on the pitch, as seen in the aforementioned incident with Carlos Tevez and Sergio Aguero.