Joshua, previously undefeated and fighting for the first time in the United States, was defending his IBF, WBA and WBO titles but was knocked down four times in the fight before the referee waved off the contest in the seventh.
Joshua said he could have fought on but had no harsh words for the referee.
"I want to fight. I am never one of those fighters to disrespect a referee like, 'he should have done this' or 'he should have done that,'” he added.
Mayweather fails to knock out YouTuber Logan Paul in eight rounds
“He called it off when he thought I couldn’t fight. It’s a shame. But I don’t want anyone to drown in their sorrows."
The defeat was a setback but Joshua said he would be back.
"Boxing is a tough sport. I trained hard, I stayed dedicated. And I just got beat by a good fighter tonight," he said. "It'll be interesting to see how far he goes but good luck to him.
"I gotta bounce back. This is all part of the journey. Fighter by heart, boxer by trade."
Ruiz had not been given much chance of beating the champion given he had just five full weeks to prepare after Joshua's scheduled opponent, Jarrell Miller, tested positive for performance-enhancing drugs.
Ruiz was dropped to the canvas in the third but the heavy brawler came back to down the Brit in the same round and Joshua was lucky to survive.
Joshua appeared to recover and worked his jab well over the next few rounds but Ruiz landed big body shots in the sixth to put the champion on the back foot.
Joshua went down again in a flurry of Ruiz punches with nearly two minutes left in the seventh and while the British fighter got off his knees just in time to beat the count his legs looked like jelly as he made his way to a neutral corner.
The referee asked him if he was okay to continue before waving his arms to end the fight, prompting wild celebrations in the ring by Ruiz and his trainers.
"This is what I have been dreaming about," Ruiz said. "This is what I have been working hard for. I can’t believe I just made my dreams come true. I just want to thank my team and my family. The sky is the limit, baby.”
Ruiz said being knocked to the floor in the third round only spurred him on.
“That was my first time getting dropped on the floor,” he added. “It just made me stronger. It just made me want it more. I just had to knock him down back.”
‘Let’s complete the journey’ - Clarke on Olympic boxing dream
Price bidding to follow in Adams' footsteps ahead of Tokyo debut