While Dekkadeci makes a good case, I'd like to contest the statement that the last chord is the dominant of the new key in "Livin' On a Prayer".
The basis of my argument is that I don't believe that the song modulates to G minor, but rather to B♭ major. I believe that the song starts with the verses in E minor, then the choruses all end up in the relative major (G major). It's not much of a difference, because it's all the same notes from the relative major to the relative minor, but it definitely sounds much more major in the chorus than the verses. It's still a 3-semitone modulation, and the D chord does lead to a Gm chord, making a V-i, but I wouldn't say that move is what tonicises the B♭ key. I'd argue that the song modulates not through any special effort to line up the chords into a smooth modulation, but rather simply moves everything up a minor third.
Interestingly, one thing I noticed is that the notes sung over the modulation are G-A-B♭, which is surprisingly smooth for such an abrupt modulation, as it runs up to the tonic degree using notes inside G major until the modulation actually occurs.
Of course, it's still useful to notice the effect Dekkadeci astutely points out, as it's always great to notice little things like that. If one wanted to do the same modulation, they might try that V-i move, and likely to great effect.