I had something similar happen to me. It was just as you've described- a very painful muscle spasm, causing intense pain underneath the rib cage. You could see a big bulge during this spasm. That in itself was scary. For some time afterward, I could feel a big hard lump with my hand. It was all very scary because I thought that my stomach was somehow coming apart. I pushed the bulge with the heel of my hand into the abdomen. I have a sliding hiatal hernia, which I was certain had caused the bulge. My doctor said it could have been a muscle spasm.
Don't be afraid to see your doctor about this pain. You might need some tests. My doctor gave me the impression that my experience was quite common.
flowergirl