The fourth bracha of Birkas Hamazon was introduced by Rabban Gamliel in Yavneh. The occasion was the permission granted by the Romans to bury the dead of Beitar. In the heroic but futile Bar Kochva revolt, thousands were massacred at the fortress of Beitar. Hadrian, the Roman emperor, prohibited their burial. Thus, their corpses were left lying in the fields around Beitar for years. When permission was granted at long last to bury them, the chachamim uttered the blessing "Hatov vehameitiv." The bracha was joined to Birkas Hamazon because it is a prayer that is spoken in joyous gratitude.
Adapted from World of Prayer by Rabbi Elie Munk