How can I remove a key that is stuck in a lock?
When a key is stuck in a pin-tumbler lock, what that usually means is that one of the pins has dropped down into the key's cuts but isn't lifting back out of the way so the key can be withdrawn.

There are several possible causes. One is that the key was cut badly and doesn't have enough of a slope to lift the pin as it is pulled back. Uncommon, though sometimes done deliberately to trap a key in the lock so it can be used as a semi-permanent thumb turn.

But usually the problem is that the plug (the rotating part of the lock) is not properly lined up with the shell. For the bottom pins to lift, they need to be aligned with the chambers in the shell that hold the top pins. If the key is slightly rotated, that alignment doesn't occur and you can't remove the key...

... But the more likely malfunction scenario involves front-to-back misalignment. If the hardware holding the plug in the shell (usually the tailpiece screw or screws) becomes loose, the plug can slide toward you as you start to pull the key out, misaligning it and trapping the key. (This doesn't become a problem while inserting the key because there's a hard stop in that direction.)

I'm betting on that being the cause here. If so, pressing the plug inward with one hand while removing the key with the other will probably work, for the same reason that inserting the key worked; you'll be using the plug's shoulder as an alignment reference point.

Try it.

If that does the trick, your lock needs to be dismounted and the tailpiece screws (or equivalent) need to be tightened. Don't delay too long on that, or you may be facing more serious malfunctions.

If this doesn't solve it, we need more detail about exactly what you did and the current state of the lock. It may be necessary to disassemble things to resolve this. Which is sometimes challenging if you can't use the proper key.

(Courtesy of ORK Security Services -- full-service, very part-time, locksmithing)