THE FOURTH BERACHAH OF BIRKAS HA'MAZON
Gemara
(Rav Masnah): On the 15th of Av they were able to bury those killed in Beitar. Therefore, it was a Yom Tov.
(Rav Masnah): Ha'Tov veha'Metiv (the fourth Berachah of Birkas ha'Mazon) was enacted in Yavneh on the day that they buried those killed in Beitar;
We say "ha'Tov" because Hash-m preserved the bodies from decaying. We say "veha'Metiv" because we were allowed to bury them.
Berachos 45b: Workers do not stay to hear ha'Tov veha'Metiv, for it is only mid'Rabanan.
46a - (Beraisa #1): Birkas ha'Mazon is two or three Berachos (alternatively - it may be divided among up to three people without splitting any Berachah).
(Beraisa #2): It is three or four Berachos.
Suggestion: Each Tana holds that there is an additional Berachah when there is a Zimun. Tana #2 holds that ha'Tov veha'Metiv is mid'Oraisa, therefore he counts one more Berachah (or person).
Rejection #1 (Rav Yosef): Surely, ha'Tov veha'Metiv is mid'Rabanan, for workers omit it!
Rejection #2 (R. Yitzchak bar Shmuel): Surely, ha'Tov veha'Metiv is mid'Rabanan, for it begins with "Baruch" but doesn't end with "Baruch";
(Beraisa): All Berachos begin and end with "Baruch," except for Berachos (Rishonos) on food, on Mitzvos, and a Berachah that follows another Berachah, and the last Berachah of Kri'as Shma;
Ha'Tov veha'Metiv begins with "Baruch" but does not end with "Baruch". This shows that it is independent (it was enacted later; it is only mid'Rabanan).
Rejection #3 (Rav Nachman bar Yitzchak): Surely, ha'Tov veha'Metiv is mid'Rabanan, for (some say that) it is omitted in a house of mourners!
(Beraisa): In a house of an Avel, we say ha'Tov veha'Metiv (for the fourth Berachah of Birkas ha'Mazon);
R. Akiva says, we say, "Dayan ha'Emes."
Question: Does the first Tana say that we say ha'Tov veha'Metiv but not Dayan ha'Emes?!
Answer: No, he means we say even ha'Tov veha'Metiv.
49a (Aba Yosi ben Dosta'i or Rabanan): One must mention Malchus (Hash-m's kingship) in ha'Tov veha'Metiv;
(The other of Aba Yosi ben Dosta'i and Rabanan): One need not mention Malchus in ha'Tov veha'Metiv.
The first opinion holds that ha'Tov veha'Metiv is mid'Rabanan (it is an independent Berachah by itself, therefore it needs Malchus). The latter opinion holds that it is mid'Oraisa (it follows the previous Berachos of Birkas ha'Mazon. Malchus in the first Berachah suffices for all of the Berachos.)
(R. Yochanan): One must mention Malchus in ha'Tov veha'Metiv.
Question: Is the Chidush that every Berachah needs Malchus? R. Yochanan already taught this!
Answer #1 (R. Zeira): He teaches that two Malchuyos are required. The second is to compensate for the lack of Hash-m's Malchus in Boneh Yerushalayim.
Question: If so, a third Malchus should be required, to compensate for not mentioning Malchus in Birkas ha'Aretz!
You must say that we need not compensate for (omitting Malchus in) Birkas ha'Aretz, because it is adjacent to another Berachah (the Malchus of Birkas ha'Zan counts for it).
Likewise, we need not compensate for Boneh Yerushalayim, because it is adjacent to another Berachah!
Answer: Indeed, we need not compensate for Boneh Yerushalayim because it lacks the Malchus that every Berachah needs, because it is adjacent to another Berachah. Rather, it is improper to mention Malchus Beis David without mentioning Malchus Hash-m. We compensate for this in ha'Tov veha'Metiv.
Answer #2 (Rav Papa): Two Malchuyos are required in ha'Tov veha'Metiv, in addition to the usual Malchus at the beginning (Baruch Atah... Melech ha'Olam). (We say ha'El Avinu Malkeinu... ha'Kel ha'Melech ha'Gadol.)
Rishonim
Rif (34a): The Tana who says that Birkas ha'Mazon is three or four Berachos does not count ha'Tov veha'Metiv, for it is mid'Rabanan.
The Rif (Berachos 36a) brings the discussion of Malchuyos verbatim.
R. Yonah (DH ha'Tov): A Berachah Samuch l'Chavertah (that follows another Berachah) does not begin with Baruch. However, since ha'Tov veha'Metiv is mid'Rabanan, it is like a Berachah by itself, so it (starts with Baruch and) needs Shem and Malchus. This is obvious, so we asked what was the Chidush of R. Yochanan. It is not fitting to mention Hash-m's Malchus next to mortal Malchus (Beis David), for this connotes that they are comparable. Those who do so err; if it was permitted, we would not need to compensate in ha'Tov veha'Metiv.
Rambam (Hilchos Berachos 2:7): The fourth Berachah of Birkas ha'Mazon must mention Malchus (Hash-m's kingship) three times.
Rosh (4:17): Ha'Tov veha'Metiv is mid'Rabanan.
Rosh (Berachos 7:22): Ha'Tov veha'Metiv was fixed in Birkas ha'Mazon, which is entirely thanks. The destruction of Beitar cut off the Keren of Yisrael and it will not be restored until Ben David will come, therefore it was put next to Bonei Yerushalayim. The third Berachah should have mentioned Malchus, just it is improper to mention Hash-m's Malchus next to mortal Malchus (Beis David). Therefore, it was put in ha'Tov veha'Metiv. Rav Papa teaches that it requires two mentions of Malchus other than its own. Since we enacted Malchus corresponding to Bonei Yerushalayim, we also enacted corresponding to Birkas ha'Aretz.
Question: Ha'Tov veha'Metiv is a long Berachah. Why doesn't it end with Baruch?
Answer #1 (Rosh and R. Yonah DH uv'Kan, citing a Medrash): It does not end with Baruch because it was enacted to be a short Berachah. Additions were added later.
Answer #2 (R. Yonah): It is considered a short Berachah because it is just an (albeit long) list of descriptions of Hash-m.
Answer #3 (Rashba, brought in Kesef Mishneh 2:7): Chachamim did not want to make it greater than the previous Berachos, which are mid'Oraisa.
Poskim
Shulchan Aruch (OC 189:1): In the fourth Berachah we say three Malchiyos - 'Elokeinu Melech ha'Olam', 'ha'Kel Avinu Malkeinu', and 'ha'Melech ha'Tov'.
Rashba (brought in Beis Yosef 188 DH veha'Rashba): Those who say in the third Berachah 'u'Malchuscha u'Malchus Beis David' or 'Avinu Malkeinu' err, for in ha'Tov veha'Metiv this is considered a mention of Malchus. However, this is not so clear. In many cases a Berachah Samuch l'Chavertah has such an allusion to Malchus, e.g. 'Melech Memis u'Mechaye', 'ha'Melech ha'Kadosh', 'Mechal Lanu Malkeinu',...
Answer (Beis Yosef): Perhaps even though a Berachah Samuch l'Chavertah does not need to mention Malchus, it may. For every Berachah the Rashba mentioned, if it were not Samuch l'Chavertah the mention of Malchus would suffice. We do not mention Malchus in Birkas ha'Aretz, lest it be greater than Bonei Yerushalayim.