Earls scored his second try of the game after 68 minutes when he ran in at the corner to finish off a fine move involving Sexton, O'Driscoll and D'Arcy.
After half-time, Mafi was sin-binned after a high tackle on Rob Kearney but O'Gara kicked the 14 men back in front after Gordon D'Arcy had transgressed at a ruck.