Ilias Chair put Rangers ahead after 20 minutes and they seemed to be in control before Michael Smith's 38th-minute equaliser - the striker's first goal since February.
But at the end of the first half, having twice hit the woodwork, Osayi-Samuel scored in fine style and Lyndon Dykes then thumped in a penalty after Dan Barlaser's handball.
Freddie Ladapo pulled a goal back with six minutes remaining but Rangers held out for the win despite some uncomfortable moments in the final stages.
Osayi-Samuel was outstanding for the hosts and almost gave them an early lead when he fired against the outside of the post.
It was a temporary reprieve for Rotherham, who have now lost three of their past four matches.
Osayi-Samuel set up the opener, retrieving Chris Willock's left-wing cross and then tricking his way inside to tee up Chair, whose deflected shot brought the Moroccan's second goal in as many games.
QPR conceded 76 goals last season and though they have been better defensively this term, they remain vulnerable.
The 17th they have shipped this season came after Willock, who was otherwise impressive, miscued an attempted volleyed clearance near his own penalty area.
Wes Harding sent in a cross from the right flank and Smith drifted between Rangers centre-backs Conor Masterson and Yoann Barbet to head the Millers level.
They remained level despite a glorious chance falling to Osayi-Samuel, whose shot from point-blank range after good work by Chair was diverted onto the post by Angus MacDonald.
Osayi-Samuel made amends with a superb goal to restore the home side's lead.
The winger exchanged passes with Geoff Cameron and then breezed past MacDonald and Joe Mattock - causing them to bump into each other - before firing into the roof of the net.
And when Barlaser inexplicably handled the ball when under limited pressure from Chair, Scotland striker Dykes helped himself to his fourth goal since joining QPR during the summer - all of them have come from the penalty spot.
The second half was much less eventful and Rotherham were glad to see the back of Osayi-Samuel, who continued to worry them before being taken off late on.
They struggled to create clear-cut chances, although they were given hope when Ladapo nodded in the rebound after Michael Ihiekwe's header from Jamie Lindsay's right-wing cross had come off the post.