Sometimes a piece of music temporarily moves into a new key. This is called modulation. It is very common in traditional classical music; long symphony and concerto movements almost always spend at least some time in a different key (usually a closely related key such as the dominant or subdominant , or the relative minor or relative major), to keep things interesting. Shorter works, even in classical style, are less likely to have complete modulations. In most styles of music, a slow, gradual modulation to the new key (and back) seems more natural, and abrupt modulations can seem unpleasant and jarring. But implied modulations, in which the tonal center seems to suddenly shift for a short time, can be very common in some shorter works (jazz standards, for example). As in longer works, modulation, with its new set of chords, is a good way to keep a piece interesting. If you find that the chord progression in a piece of music suddenly contains many chords that you would not expect in that key, it may be that the piece has modulated. Lots of accidentals, or even an actual change of key signature, are other clues that the music has modulated.
A new key signature may help you to identify the modulation key. If there is not a change of key signature, remember that the new key is likely to contain whatever accidentals are showing up. It is also likely that many of the chords in the progression will be chords that are common in the new key. Look particularly for tonic chords and dominant sevenths. The new key is likely to be closely related to the original key, but another favorite trick in popular music is to simply move the key up one whole step, for example from C major to D major.