Here are some of my thoughts, I hope you find them helpful.
Laurence Payne is right, practice is the most important ingredient here.
You indicated that you view "transcription" and being able to pick up a song "in real time" as it's happening as a different skill. While there are some small differences, in my experience they are largely the same skill.
In my personal case, I started out by laboriously working out songs by ear. As I child I would sit in front of the piano trying to work out nursery rhymes and christmas carols (just the melodies of course). In my teens, I really wanted to play "feeling good"; I liked (and still do) the song a lot, and it sounded doable. Anyway, there wasn't that much available on the internet in the mid 2000s like there is now, and it took me weeks and weeks and weeks to get it right (or right-ish).
I'm now in my 20s and I often play new songs by ear as I hear them at jam sessions, playing with friends etc. I will go into to details about what the process of picking up a song on the spot is actually like, but the key point is, I absolutely got there by practicing doing it more slowly.
For my personal journey this included mainly:
1) Working out existing music by ear (initially a very laborious and difficult process, my main incentive being I had no other way to do it). If your ability is up to this, then get into the habit of doing it for every single song you learn, or at least making a good attempt before looking up a transcription.
(As a side note, just playing games where you try and recognise chord types from hearing them is also useful.)
2) Writing music. The process of trying to put melodies and chords in your head onto an instrument helps you to learn to pick up others' music too.
3) Soloing. I fell in love with the blues in my teens, and while the paint-by-numbers approach of learning scales and playing from them can help you get into it, eventually you get to the stage where you're playing what's "in your head" i.e. you know what it's going to sound like before you play it. I believe this is called audiation, and again this comes with practice.
4) Sight-singing. I read music, if you do to, trying to count the steps between notes in your head and sing a melody before you've ever heard it is sort of like "backwards" working out by ear and I'd recommend it. Eventually you can sing any interval directly without mentally counting up a scale/half steps. Then, conversely it's much easier to know what notes are from hearing them, much like how speaking a second language and understanding a second language go hand in hand. (Sightreading the rhythm part less important for this but also valuable)
Now, your musical tastes and areas of practice might differ (it of course isn't necessary to like blues or read music to play by ear, these are just good examples). The point is that the common denominator is training your ear through lots and lots of practice, this is the most important thing.
The above is the answer to what you "should do" in order to get to the stage where you can pick up songs very rapidly. The rest of this answer is just to give you an idea of what the roadmap ahead will look like if you do go ahead with this effort, what you might gain from it, and some of the practicalities of playing by ear "on the spot". It might be useful or interesting to you, but the key information is up there^^^.
So one thing having a "good ear" gives you is an immeasurably greater understanding of all other aspects of music; you start to see inner workings of the music you play, and listen to.
People will tell you that music theory will help you to work out songs by ear, and while that's true, what they often miss out is that working out songs helps you understand music theory. The more you work out, the more you will start to recognise patterns. In a way, this is what most of music theory is, and you'll get a lot of it for free just by learning from music itself (and depending on your favourite genre, there may well be a lot of content that classical music theory doesn't particularly cover but nevertheless follows patterns and shapes).
You can get to a point where, when hearing a song you almost transcribe it automatically. When I listen to the radio in the car for example, if it's a relatively simple song then I'm mentally tracking the chords and notes being played involuntarily; much as when you see a written word, you can't help but read it. Because of this, you just start to notice patterns in music everywhere.
This means that, in addition to being able to use your ears to work out songs quickly, once you hear a few bars of a song, you already have a reasonable guess about what kind of things are likely to happen. Sometimes you'll see the tune unfolding in a particular direction and see what it'll do before it even gets there. And even if you don't see it before it happens, once it's happened you "get" what it's done, so it's not hard to remember when it rolls back round to that part. It's just like how "sdgfjdslkjoa fogj apekg" is impossible to remember but "The red book" is impossible to not understand. You make sense of it in terms of your existing framework of meaning.
In this way, when you work out a song by ear, you can also often reduce it to its most important parts, know which are the bits that are most important for the skeleton of the song, and what's more there for "decoration". If I tell you a joke, and you want to tell it to someone else, you're not going to recount it work for word, you're going to remember the key concepts that make the joke word, and fill the gaps with what works.
Every now and again a bit of a song will really surprise you. In these cases it can be much harder to pick out an exact chord or run of notes at the first listen. It might be something harmonically, rhythmically, or melodically complex, that you're playing in an unfamiliar idiom, or something that is just straight up unexpected in that context. Or it might be that your brain for some reason just can't pick out a particular chord, or run of notes. In practice, if you have some experience playing within a genre, there are often ways to play something inoffensive that will bridge the gap between the holes in your understanding.