When you fire most semi-automatic pistols, the hammer strikes a pin which transfers force to the current round. The pin specifically connects with a point on the shell detonating the primer.
The primer is a very small explosive charge, not enough to get the bullet moving, but just enough to get the gunpowder burning. The burning powder will cause the “explosion” that propels the bullet.
I put “explosion” in quotes because, technically, gunpowder just burns quickly and violently, it doesn’t actually explode. But, the difference is mostly academic.
The force from the gunpowder propels the round down the barrel, but it also causes the slide to cycle. At this point, the slide will cycle back, extracting and ejecting the spent shell casing, and retrieving a fresh round from the magazine. This will also recock the hammer, preparing the weapon to fire again. You can find cutaway .gifs of this, if you really want to see it in action.
The slide is spring loaded to close on it’s own, so once it’s cycled open, the guide spring will close the slide with a fresh round in the battery.
When you jam the slide open a few things can happen. On some handguns, the battery will misalign with the firing pin. The shooter can still pull the trigger, the hammer will drop, but the pin will either fail to connect with the round, strike the round incorrectly (missing the primer), or (with some automatics) opening the slide will temporarily disable the connection between the trigger and hammer.
If someone attempts to fire the pistol while the slide is open, there’s a couple possibilities. On a gun where the trigger to hammer connection is disabled, the trigger won’t break (the exact point the trigger releases the hammer, and yes you can easily feel this when you’re shooting) instead the trigger will draw back with little tension and (in some cases) click slightly at the point where it would normally break.
On a pistol where the trigger to hammer connection isn’t disabled, then the trigger will draw normally, the hammer will drop, but the gun won’t go off. This can result in two situations. On a single action pistol, the user will need to manually recock the hammer before it can be fired again, since the mechanism depends on the slide cycling to recock normally. On a double action pistol, drawing the trigger back will cock the hammer. The shooter will experience additional tension on the trigger (usually a pound or so).
It’s also worth pointing out that some pistols (variants of the Walther P99 come to mind here) are designed to switch between single and double action as a safety mechanism, or are available in both single action and double action variants.
One of the Marine gun disarms begins with lunging forward to slam the hand into the slide in order to disable the pistol.
Also, it’s worth pointing out this won’t work with all handguns. Revolvers aren’t affected at all. Automatics with a fixed barrel, like the Desert Eagle, Mauser C96, or Luger Pistole Parabellum can be still be disabled by opening the slide, but getting to their slide is much more difficult.
If you’re wanting to look into close quarters shooting with handguns, then I really recommend checking out the self-defense side. With the more honest experts, you’ll get a good layout on what the strengths and limitations for the pistol are in that range. A lot of the information you’ll get otherwise regarding guns is going to assume you’ll be using them at long range. So, remember, while close quarters shooting is not uncommon, it is more specialized.
Just to add, some specific brands also release handguns with a safety feature where if the barrel is pressed against a surface (like a pistol to the back of the head execution style) they are disabled.
Not so much an intentional safety feature as a byproduct of how the Browning lock mechanism works. When you press the barrel against something it will partially unseat the battery and push the slide back. It does safe the weapon temporarily, but it’s not really an intended function, just one of those little design quirks.
Incidentally, that’s the exact quirk the marines exploit with the disarm technique mentioned above.