The 25-year-old, deemed surplus to requirements by Jose Mourinho, is Mark Hughes' ninth summer signing as he aims to improve on the west London side's 17th-placed finish last year.
Hughes told the club's official website: "He is a great player, first and foremost. You don’t play at a club like Real Madrid if you’re not.
"He has got great energy and is technically very gifted, as you would expect. He is an all-round excellent midfielder.
|THE GOAL LINE
|20/1||Junior Hoilett is 20/1 with PaddyPower to open the scoring against Man City
"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."
Granero spent two years at Getafe before returning to Los Blancos where he played 60 games in the last three seasons.
The midfielder will wear the No.14 shirt and added: "I love the passion of the English fans and from what I know QPR supporters are amongst the very best.
"When I spoke to Mark [Hughes] and Mike [Rigg], as well as Tony [Fernandes] I was convinced that I wanted to be part of this project, which has no limits.
"Players that have joined before me are as excited as I am about what QPR can become, one of the great teams in England."
QPR have bolstered their squad in recent weeks, convincing Inter Milan and Brazil No.1 Julio Cesar to head to Loftus Road, as well as Park Ji-Sung, Jose Bosingwa and Junior Hoilett.
And Hughes spoke in glowing terms about the ambition of the club: "What we are doing at QPR is having an impact on players. It is probably true to say that if we had approached certain players three or four months ago about joining the club, the suggestion wouldn’t have been entertained.
"But people now know we are serious and we are trying to do something different here. And that message is out there now which is why we are able to sit in front of quality players and once we are given that opportunity, we feel we have a good story to tell them.
"That’s why players are deciding that QPR is a great option."