At the end of a successful Mega Raid, you'll earn Mega Energy for that Pokémon regardless of whether or not you catch the Mega-Evolved Pokémon. The faster you defeat the Raid Boss, the more Mega Energy you'll receive, so be sure to invite friends and plan your lineup carefully.