The home team's goalkeeper inexplicably punched the Portuguese's shot between his legs, while the referee ignored an apparent foul in the lead up to the Argentine's strike.
Cristiano Ronaldo cannoned a free kick from 35 yards midway through the first half which Andres Fernandez - in a moment of madness - opted to punch the shot, but the ball unexpectedly bounced downwards between his legs and bounced off his backside over the line.
The home side tried to drag itself back into the cup tie, despite its fate looking all-but-sealed, but the efforts were either marginally off target or softly struck too close to Blancos captain Iker Casillas.
Carlo Ancelotti's men allowed the Rojillos to press early in the second half but sapped the life out of the game 11 minutes after the break when Angel Di Maria finished off a swift counterattack, with the referee surprisingly not blowing his whistle for a foul on Osasuna's Miguel de las Cuevas by Xabi Alonso in the build-up.
Despite the mistakes that allowed for the goals in Pamplona, the result was a fair representation of the match as Osasuna looked uninspired while Madrid never looked truly destructive.
The victory sees Javi Gracia's men eliminated from the Spanish cup, while last year's runner-up Madrid - which had nine men left on the pitch at the end of the game due to Fabio Coentrao's sending off and Alvaro Morata's facial injury - will face Espanyol in the quarterfinal stage.
The Blancos started slowly and looked disjointed in the final third, with Jese Rodriguez, Di Maria and Isco failing to put too many passes together.
Ballon d'Or winner Ronaldo was largely working on his own largely on the left wing, but was gifted a goal 21 minutes after the start when Fernandez punched his dipping free kick between his legs and in for the opener.
The home side refused to lie down and take the defeat, despite the team's fate looking all-but-certain, and Alvaro Cejudo's free kick kept Casillas on his toes when it dipped on to the roof of the net from 25 yards.
Roberto Torres definitely should have done better when shooting from 12 yards inside Madrid's box, but his effort was weak and Casillas was able to slowly fall to his left to smother the soft strike.
After the break, the Rojillos persevered for a little while longer but their spirits crumbled with 56 minutes on the clock.
The referee refused to blow for what looked like a foul from Alonso on De las Cuevas, and the visitors counterattacked up the pitch via Jese, who crosses low and firm for Di Maria to thump in low into the bottom corner to seal the result with half an hour still to play.