Fire needs three components - heat, oxygen and fuel. Remove on to kill the fire.
Nitrogen displaces oxygen (in other words is pushes it away or moves in and takes over)
You cannot use wate with electrical fires - well you can if you want alot of trouble. Dry powders and that sort of thing are messy.
So Nitrogen, being colorless and odourless, and very dangerous if you breath it is used to remove the oxygen component in case of an electrical fire - thereby straving it to death. And afterwards you are not left with alot of cleaning up to do.