Why does the needle get deflected by the magnet?

cbse
electromagnetism

#1

When the N-pole of compass needle and N-pole of magnet come close to each
other the needle gets deflected due to repulsion, (or) When the S-pole of compass needle and S-pole of magnet come close to each other (S-pole and S-pole are like poles they repel each other) and the needle gets deflected.