Locate your gas meter and shut off the gas supply to your home with the lever on the gas supply pipe next to the meter.
Open all of the windows in the room you're working in. There's a chance that residual gas may escape from the system while you're working.
Disconnect the valve from your fireplace with a wrench. Then remove the pipe that served your fireplace by unscrewing sections of it with the wrench. Take the pipe back to a point where it can be capped off.
Apply pipe sealant to the gas line cap and secure it in place at the end of the gas pipe. Add a generous amount of sealant around the joint, once it's fitted, to make sure it's sealed. Allow the sealant to dry as per the manufacturer's instructions.
Turn the gas supply to your home back on.
Check for leaks around the end of the capped-off line with a gas leak detector. Turn off your gas supply and reapply sealant if you find a leak.