There isn't really one counter to Mega Gengar. Due to Shadow Tag, you can't switch freely, and lets face it, you'll most likely lose one or two Pokemon at least to Mega-Ggengar before you can take it out. There are a few ideas, but all of them involve some amount of luck/ timing.
Chandelure @ Choice Scarf
Ability: Infiltrator
EVs: 252 Sp. Atk, 252 Speed, 4 HP
Nature: Timid/ Modest
- Shadow Ball
- Fire Blast
- Energy Ball
- Trick
Scarf Chandelure will outspeed Mega-Gengar for sure, even with Modest nature, but cannot switch in to it safely, so it has to Revenge kill. Infiltrator will by pass Substitute and OHKO Gengar with Shadow Ball. Chandelure is more viable over wifi, as it's not Uber tier material on Showdown.
Bisharp @ Life Orb/ Lum Berry
Ability: Defiant
EVs: 252 Atk, 204 Speed, 52 HP
Nature: Adamant
- Knock Off
- Iron Head
- Sucker Punch
- Swords Dance
While Bisharp doesn't outspeed Mega-Gengar, it's resistant and immune to Gengar's two STABs respectively. Mega-Gengar usually carries Substitute, and more often than not either Disable or Perish Song, meaning it frequently forfeits Focus Blast coverage. Bisharp still can't tank any special hits, but at least it's resistant to Shadow Ball and can break the Substitute.
Mewtwo @ Mewtwonite Y
Ability: Insomnia
EVs: 252 Sp. Atk, 252 Speed, 4 HP
Nature: TImid
- Psychic
- Ice Beam
- Aura Sphere
- Flamethrower/ Thunderbolt
Mega-Mewtwo Y can't switch in safely to Gengar or break its Substitute without fainting, but it can OHKO Gengar with Psychic if it's not behind a Substitute and deal it with it that way. Problem is that Mewtwo can't be bred, so you have to get lucky and get a perfect speed IV (though all legendaries in X&Y have 3 perfect random IVs when caught).
Tyranitar @ Leftovers/ Tyranitarite
Ability: Sand Stream
EVs: 252 Atk, 204 Speed, 52 HP
Nature: Adamant
- Crunch
- Earthquake
- Dragon Dance
- Stone Edge/ Super Power
So the problem with Mega-Gengar is that it packs Disbale. However, it loses Levitate meaning T-Tar can use Earthquake or Crunch to OHKO it. Sand Stream also gives some nice residual damage to Gengar, in addition to allowing T-Tar to take a Dazzling Gleam before dealing out damage.
Diggersby @ Choice Scarf/ Life Orb
Ability: Huge Power
EVs: 252 Atk, 252 Speed, 4 HP
Nature: Jolly
- Earthquake
- U-Turn
- Return
- Rock Slide/ Agility
Seriously? Diggersby? It's not as stupid as you think. But - this will only work if you face a stalling Gengar that only has Shadow Ball. Disable could really mess you up if Diggersby is choiced and Gengar is behind a substitute, so you could run an Agility Life Orb set instead.
Scizor @ Scizorite
Ability: Technician
EVs: 252 Atk, 200 HP, 56 Speed/ Sp. Def
- Bullet Punch
- Pursuit
- U-Turn
- Swords Dance
One unboosted Bullet Bunch will manage to cut Gengar's Health in half, and Mega-Gengar has no reliable method of recovery except Rest. If Disable gets you, Pursuit is the other move you can use on Gengar. Scizor can't break Substitute, but it can Pursuit trap Gengar should your opponent choose to switch out.
So as you can see there isn't one answer to Mega-Gengar. It's got high speed and advantageous typing, meaning its immune to most priority moves. There are pretty much no safe switch ins to Mega-Gengar.