Does the run count when a batter bunts and the runner on third scores before the first baseman tags the batter for the third out?

No, because the third out was made on the same play. It is no different than if the batter hits a ground ball to the shortstop or any other infielder and is thrown out at first base for the third out. However, if there are two outs and there is a runner on third and the batter hits a single into left field but is thrown out at second when attempting to turn the play into a double and the runner on third makes it home before the third out at second is recorded, the run does count. Hope that isn't too confusing.