The game cannot end on a winning run till the batter-runner reaches first base. Although this principle is not directly reflected in the rules explicitly, the following rule was put in place to cover game-ending home runs.
Rule 5.08b:
When the winning run is scored in the last half-inning of a
regulation game, or in the last half of an extra inning, as the result
of a base on balls, hit batter or any other play with the bases full
which forces the batter and all other runners to advance without
liability of being put out, the umpire shall not declare the game
ended until the runner forced to advance from third has touched home
base and the batter-runner has touched first base.
Although this only applies to cases where the runners must "advance without
liability of being put out", I must surmise that this is because a game-ending home run or walk is far more likely and common than your scenario, which I believe is one of the few where this could actually matter, and then only for purposes of official scoring.
So the answer is that both outs would count, regardless of timing, based on extending the principle behind Rule 5.08b.