Have to be very careful when dosing medications - all medications have potential to harm/kill the fish due to their tiny little organs and medication really isn't healthy for any one/animal.
Melafix, as mentioned, is controversial - but it can be used as long as it is diluted a good amount prior to use. Even then it's iffy.. I've seen some bettas have no trouble with it, others start shedding slime coating, etc. I think your guy either freaked out from being moved, or it irritated his open gills.
How did he get his gills inflamed like that? Normally it happens from things such as nitrate poisoning (not cleaning the tank enough - not siphoning out the poop each week from the substrate will build it up quickly), bacteria infection or even something dripping/sprayed into/near tank.. I accidentally placed too much green tea too quickly into a tank of one of my boys about a year+ ago and his gills went straight out like that as a result, had to treat him with AQ salt for a few days before he got better.. ended up taking over a week before they fully closed.. never used green tea since, prefer IAL/oak for tannin now.
Clean water and AQ salt would help him - AQ salt will help keep the gills clean and keep the mucus on them..
1-2 tsp per gallon, daily 100% water changes adding in the AQ salt (+ water conditioner) each time. Make sure to dissolve the salt in hot water (keep stirring it) before adding him to it.. continue the treatment until he is better, or for 10-14 days, whichever comes first.