The Milky Way and Andromeda are destined to collide and merge within the next 4-5 billion years, but I feel like there could be a chance that instead of merging, they could just eject each other. I dunno, but is it possible, and if so, how likely will it be?
A full merger may not occur on that timescale. The encounter in 4.5 billion years will take place but the galactic centers may be far enough apart that it is a "glancing blow". Regardless, the orbit will be diminished and the two will come together some billions of years later (e.g. Schiavi et al. 2021).
The basic physics here is that the Milk-dromeda system(!) has a certain amount of energy (the sum of its kinetic energy and gravitational potential energy), and the total is negative. This indicates that the system is bound.
As time goes on energy is lost from the system through radiation and also perhaps through the ejection of some gas and stars. This makes the system more bound. These processes are actually enhanced as the galaxies approach each other and their gas starts to interact (the stars are effectively point-like particles and won't collide).
Thus the net effect will always be to bind the galaxies closer together and they won't escape from each other.
That said, the fact that each of the galaxies contains billions of component stars, does mean the energy can be shared out in many different ways. It is quite likely that some (a small fraction) of the stars and gas will gain sufficient kinetic energy during the collision to escape from the system as a whole.
Here is a simulation based on the Schiavi et al. calculations. You can see the initial glancing blow followed by the merger sometime later. You can also see that a fair number (difficult to be quantitative based on this) of stars do get thrown out of the system during the merger.