Relaxation of toroidal plasma and generation of reverse magnetic fields