Check the weather to make sure you have a few days without rain and cover the ground with a drop cloth.
Use a stiff wire brush to get off loose rust and flaking paint. If you don't care about your fence having some bumpy surfaces, you can simply follow up by painting the dry gate with a primer made to be applied on top of rust. Allow the primer to dry completely.
Apply a rust stripper after scraping with the wire brush, if you do not want any rough spots on the metal. Scrub until only shiny metal is left, no rust or paint. Wash the stripper off and let the gate or fence dry completely. Within a day, paint with a primer made for outdoor metal.
Use a paint formulated to resist rust. Spray paint or regular, brush-applied paint are both fine. With spray paint, make sure it is not a windy day. If the gate is near a siding or a structure that you do not want to paint, cover it with drop cloths.