This is a fun subject. I suspect everyone does it differently.
Something I do is set my characters wandering and see what happens/turns up. When writing a first draft, the goal is to get to the end; the state of the writing is immaterial. Once you have a story, you can plan – if you want to.
For example, my pair of protagonists turned up in a new land, and three guides had been sent to take them where they need to go. I had no idea what would happen in between. So I set them off walking. Suddenly the guides became nervous and had everyone hide. Some strange folk were approaching and – for some reason – the guides wanted to avoid them. I had some fun with what the strangers did and, of course, afterwards the protags wanted to know what was going on.
In subsequent edits, the strangers became a major plot point – well, the organisation they belonged to did – but if I hadn’t set off wandering, none of it would have happened, and the organisation would never have come to be.
For me, it’s a case of letting go in the early stages and seeing what turns up. i.e. Just write and be prepared to throw away stuff until something sticks.
You do need to get to the end, though, imo, and then iterate on the story. Once you have a beginning, a middle, and an end, then all sorts of things turn up; too many, quite often.
Of course, some genres are more limiting.
That said, I believe that knowing your ending asap is crucial; so you can write towards something. There’s nothing stopping you changing the ending, if you think of a better one (or need to move it a bit). If you’re not writing towards something, then you’re just writing, and then it’s easy to spend too long in the woods when you need to be on the path.
And an initial ending doesn’t have to be a clever plot twist; it can simply be: the protagonists get home safely; or the protagonist dies; or whatever. The humdinger of an ending will come to mind at some point as the story develops.
Other quick suggestions:
– Apropos of nothing, have two characters (more will slow you down) chat about something you think is unrelated to the story. Dialogue is easier to write than narrative, so there’s little to hold you back.
– Turn left instead of right. Revisit a scene and explore what happens when one or more characters changes their behaviour or action. They took the elevator, so have them take the stairs. They drank coffee, have them drink tea. And so on.