Lopez, who accepted the fight on short notice after Ortiz's planned opponent Andre Berto failed a doping test in May, turned in the performance of his life and won by a TKO when Ortiz himself told the referee he could not carry on.
"I couldn't close my mouth," Ortiz said in the ring before being taken to a hospital. "My corner wanted me to continue, but I just couldn't."
Ortiz had been ahead on all three judges' scorecards at the point the fight ended.
It leaves Ortiz's career in limbo - along with that of Saul Alvarez. The WBC light middleweight champion had just had a September 15 superfight confirmed against Ortiz - subject to the 25-year-old coming past Lopez.
Alvarez had also seen a planned defence against Paul Williams fall through when the boxer was paralysed in a motorcycle accident, while James Kirkland accepted and soon after pulled out of an offer to fight him.
But Lopez said the timing of the announcement inspired him to victory.
"I felt disrespected," Lopez said. "I wanted to mess up their plans."
"I'm a man, and I'm not intimidated by anything. I have a big heart. He tried to intimidate me, but it didn't work. Victor has no heart."
"This was my Rocky moment, and I wasn't going to let it go," the 27-year-old added. "This is my Rocky moment. I didn't plan ahead. I didn't plan a single hour after the fight. I didn't bring clothes to wear. I didn't know what was going to go on after the fight. My plan was to get in here and go from there. I'm still in somewhat of a shock. We did it. We did it."