To expand on the above, here is the official Major League Baseball rule about what is an RBI:

RUNS BATTED IN

10.04

  1. Credit the batter with a run batted in for every run which reaches home base because of the batter's safe hit, sacrifice bunt, sacrifice fly, infield out or fielder's choice; or which is forced over the plate by reason of the batter becoming a runner with the bases full (on a base on balls, or an award of first base for being touched by a pitched ball, or for interference or obstruction).
    1. Credit a run batted in for the run scored by the batter who hits a home run. Credit a run batted in for each runner who is on base when the home run is hit and who scores ahead of the batter who hits the home run.
    2. Credit a run batted in for the run scored when, before two are out, an error is made on a play on which a runner from third base ordinarily would score.
  2. Do not credit a run batted in when the batter grounds into a force double play or a reverse force double play.
  3. Do not credit a run batted in when a fielder is charged with an error because he muffs a throw at first base which would have completed a force double play.
  4. Scorer's judgment must determine whether a run batted in shall be credited for a run which scores when a fielder holds the ball, or throws to a wrong base. Ordinarily, if the runner keeps going, credit a run batted in; if the runner stops and takes off again when he notices the misplay, credit the run as scored on a fielder's choice.

The previous work was reformatted for easier reading, but is otherwise exactly as written in all baseball rule books.