Berachos, Chapter 6, Mishnah 2. This Mishnah deals with the question of the status of someone who recited a berachah that is not the correct berachah for the food item in front of him.
"Beirach al peiros ha'ilan borei pri ha'adamah - yatza":
Someone who recites a berachah over fruits of the tree, whose proper berachah is "borei pri ha'etz", and instead said "borei pri ha'adamah" - which is the correct berachah for what grows in the ground, for vegetables - has fulfilled his obligation after the fact. The reason is this: although the fruit grows on the tree and "borei pri ha'etz" is the berachah suited to it, ultimately it too comes from the ground. Therefore, after the fact, once it has already been said, he has fulfilled his obligation.
"Ve'al peiros ha'aretz borei pri ha'etz - lo yatza":
In the reverse case, someone who recited "borei pri ha'etz" over a vegetable that grows from the ground and not from a tree has not fulfilled the obligation of the berachah, and his berachah is of no help. Since the vegetable does not grow from a tree, what he said is simply not true, and therefore he must recite the proper berachah: "borei pri ha'adamah".
"Al kulam im amar shehakol nihyah bidvaro - yatza":
This ruling applies to all the items, and it even refers back to the various items listed in the first Mishnah, including even wine and bread: someone who recites "shehakol nihyah bidvaro", which is the most inclusive and general berachah of them all, has fulfilled his obligation after the fact. He has fulfilled the mitzvah and the berachah, and he is not required to recite an additional berachah.
In summary: We learned that someone who recites "borei pri ha'adamah" over fruits of the tree has fulfilled his obligation after the fact, since the fruit too comes from the ground; someone who recites "borei pri ha'etz" over produce of the ground has not fulfilled his obligation, since there is no truth in what he said; and someone who recites "shehakol nihyah bidvaro" over anything at all has fulfilled his obligation after the fact, because this is a general berachah that includes everything.