There would be a leadership vote in the party that the ex-PM had led. If that party had a majority in the Commons, or a reasonable prospect of forming a coalition with a majority, the party's MPs would presumably install a temporary leader to serve until the leadership election was complete.
UK elections do not directly elect a prime minister, no matter how many people want to see them that way. The only way a general election can be rapidly followed by another one is if no party has a majority, and it becomes clear after several attempts that no coalition can be formed.
Other technical possibilities, not politically viable IMHO, would be:
Someone in the same party with a safe seat resigns from the Commons, and the former PM stands in the by-election and returns to the Commons. That would only work if the former PM was well-liked by their party and a volunteer could be found immediately. Immediately elevating the holder of the safe seat to the Lords to free the seat would almost certainly be seen as corrupt; the volunteer would have to be out of Parliament for a few months.
The former PM could be elevated to the Lords and be PM there. That is not politically viable these days and granting the peerage would also be seen as corrupt.