In baseball, the fourth out is a legal out made by the defense after three outs in a half-inning already have been recorded. According to the rules, the third out does not cause the ball to become dead; if the fielders make a subsequent out that prevents a run from scoring, this out will supersede the apparent third out, thus becoming the recorded third out.  For statistical purposes, the apparent third out is "undone" and the fourth out's result is recorded instead. This is not the same as four strikeouts in an inning.
When runs score
The motivation for making a fourth out is to nullify a scored run, by either putting out the runner who had scored (on appeal, if s/he had failed to tag up after a catch) or putting out an additional runner who is forced to advance.
No run may score on an inning-ending play in which the third out is a force out or on the batter before he reaches first base. Put in other words, force outs count before runs are scored. It is common that a runner reaches home plate a moment before the third out is made by force out. Such a case is routine; the runner doesn't score but is counted as left on base.
It is also common that the third out might come on a non-force tag out after another runner reaches home plate. By extension of these two rules, the "fourth out" covers the case where the third out is not a force out, but a subsequent out is. Since the force out counts before the run scores, it must also count before the third out.
The situations where a fourth out may be recognized are exceedingly rare, but some examples follow:
Example: An appeal force out
Suppose three men are on base with two outs, and the batter hits the ball within the field of play for an apparent single. Two important facts are required: one being that the ball has not become dead (as when the ball leaves the field as in a ground rule base hit) and the second being that the ball has not been caught before it strikes the ground. The runner from third base proceeds to touch home, scoring easily. The runner from second base touches third and attempts to score, but is thrown out at home plate. Meanwhile, the runner from first base, on his way to third base, misses second base. Now we apparently have three outs and one run scored. RULING: The fielders have a viable appeal play at second base. If they are alert enough and understand the rules regarding fourth outs, they may make a live ball appeal that the runner missed second base. If such an appeal is made, the runner from first base is out on a force out, because he failed to touch his force base (second base). The force out, according to the rules of baseball, means that the batter is credited with a fielder's choice and not a single. Since no run may score on a play where the final out of the half-inning is a force out, this out prevents the runner from third from scoring. This rule merely places the occurrence of the force out before any tag play when it ends the inning. Thus the runner from third is marked as left on base and his apparent run does not count; the runner from second is also left on base, and his out is nullified; only the runner from first is out on the appeal force out, which now becomes the actual third out. (The batter, having become a runner, is also left on base.)
Example: A non-appeal out
Suppose there are runners on second and third base with two outs, and the batter hits a ground ball to third base. The runner from third scores, but the runner from second base is tagged out for the third out. Since the runner from third reached home plate before the third out was recorded, and the third out was not a force out or on the batter-runner before reaching first base, we seem to have three outs and a run scored. However, suppose that the batter-runner fell down on his way to first base and was injured, unable to walk (or that, having seen the runner tagged out, turned around and headed for the dugout before reaching first base). Then suppose that the fielders throw to first or tag the batter out. Since no run can score if the last out is made on the batter before he reaches first base, this fourth out prevents a run from scoring. Thus the runner from third is marked as left on base and his apparent run does not count; the runner from second is also left on base and his out is nullified; the batter-runner is out, which now becomes the actual third out.
Example: A quick fourth out
There are runners at first and third with two outs. The runners are attempting to steal on the pitch. The batter grounds to the shortstop. The runner from third base reaches home; then, the shortstop tags the runner who has rounded second (third out). The shortstop then throws to first base, which beats the batter-runner for the fourth out. The fourth out is on the batter before he reaches first base, so it replaces the apparent third out and nullifies the run.
Example: A missed fourth out
On April 12, 2009, in a game between the Los Angeles Dodgers and the Arizona Diamondbacks, the Dodgers scored a run because the Diamondbacks failed to record a fourth out. There were runners on second and third with one out when the batter hit a line drive back to the pitcher. The runner on third scored without tagging up before the runner at second was tagged out. The Diamondbacks left the field, thinking that the inning was over and the run did not count. However, tagging the runner at second, who failed to tag up, was not a force out so the run was not canceled. After all the defensive players had left fair territory, Dodgers manager Joe Torre talked to the umpire and claimed the run. There were no Arizona players left on the field, so nobody could tag third base and appeal that the runner had not tagged up. If they had done this before leaving the field, it would have become the actual third out and the run would not have scored.