A compass needle is a small bar magnet. When it is brought near a bar magnet, its magnetic field lines interact with that of the bar magnet. Hence, a compass needle shows a deflection when brought near the bar magnet.