Here is what Bulbapedia says on the matter:
In the event of a tie in highest IVs, the IV that determines the Pokémon's characteristic is decided in the following manner: Start with the Pokémon's personality value mod 6. The result is an index number of a stat in this order: HP, Attack, Defense, Speed, Special Attack, Special Defense. In the event of a tie in IVs, the first IV checked is the IV corresponding to that index number. If that IV is not part of the tie, the game moves on to the next index number in the aforementioned order. If it goes past 5 (Special Defense), it wraps around back to 0 (HP). When the game finds an IV that is part of the tie, that is the IV that will determine the characteristic displayed.
This probably doesn't make much sense to a lot of people. Basically, it chooses one of the stats based on the Pokemon's personality value.