Why does a compass needle get deflected when brought near a bar magnet?
A compass needle is a small magnet that can rotate freely.
The magnetic field of the bar magnet exerts a torque on the compass needle.
The needle therefore turns and aligns itself along the magnetic-field direction at that point.