Lopez stepped in as a replacement after Andre Berto failed a drug test and he bravely stood and traded with Ortiz, who was ahead on the judges scorecards when he quit the fight due to a broken jaw.
Ortiz's promoters, Golden Boy, had already pencilled in a future fight with Saul Alvarez, but Lopez scuppered this showdown as he pounded the heavily favoured Californian to a halt.
Lopez was checked by the ring doctor after an illegal right behind the head stunned him in the fifth, but he shrugged off this punch and waged a close quarters battle with Ortiz.
The crisper, quality punches appeared to come from Ortiz, but he was being dragged into a dogfight and was flagging before a left hook from Lopez jolted his jaw in the ninth.
Ortiz, who was ahead 86-85, 87-84, 88-83, struggled to close his mouth at the end of the round and informed the referee he was unable to continue, sparking wild scenes of celebration in the Lopez corner.
"I told everyone I was going to shock the world," Lopez said. "
"I'm excited. I had to fight the fight of my life to win. I knew I caught him every round. I might not have thrown the majority of the punches, but the ones I was throwing, I knew I was connecting."
Argentine Lucas Matthysse raised his record to 31-2 (29 KO) with a TKO at the end of the fifth round against Humberto Soto.