One was in his last rakaat, and a gas was about to come out, but it goes back in. So it goes out and in again.

And then there was a bit of odor.

Does it invalidate the prayer?

If there was odor yes.