Flagyl, or metronidazole as the generic version is called, is really a horrible tasting medication and can be a nightmare to get in your cat. I've taken Flagyl myself and it even leaves a bad taste in your mouth. It is the best treatment for diarrhea though.
Foaming at the mouth is common when a cat gets something it his mouth that he doesn't like. It could be caused by anything bitter tasting. It's nothing dangerous, just unpleasant for the kitty. It's mainly an attempt to get the stuff out of their mouths. It's hard to know if any medication was swallowed or if it all came out with the foam. To me on the safe side I'd wait until tomorrow to give another dose.
To get the pill in the cat I would recommend using a "piller" that you use to basically shove it down the cat's throat so that he won't taste it. You can get them at most pet stores. You could also try to coat the pill in butter or something similar your cat likes to mask the taste and help it go down easier. Nutrical could help. Some people swear on pill pockets but I've never tried them so I can't say. Don't try to crush it up and mix it with food. The smell of it is really strong and your cat won't touch it. I've tried to mix it with everyting under the sun and not even my all eating dog will touch it.
Another option, which can be costly, is to get a flavored liquid version of the medication made at a compound pharmacy. I know people that have had a lot of luck with that. Sometimes it's a lot cheaper to get a medication from a compound pharmacy and sometimes it's more expensive. You just have to check. I get medication for one of my cats from Roadrunner pharmacy that specializes in pet medications. Your vet has to call in the prescription to them and they ship it to you.