Ultimately, the moment of death consciousness is all that counts. That consciousness, however, is of course partially conditioned by all the good and bad deeds one has performed in the past, especially since one's life tends to flash before one's eyes just before that last moment, leading one to often cling to this or that memory or idea.
Technically, there are four potential types of karma that determine the nature of the last moment of one's life (Vism XIX.15):
garu-kamma (weighty karma) - if one has killed one's mother or father, for example. These types of karma outweigh any other possible result; one who has performed these at some time in this life cannot help but go to hell in their next existence.
bahula-kamma (frequent karma) - if one has performed a certain karma with great frequency, this will be the next candidate for adherence at the moment of death.
aasanna-kamma (dying karma) - if there is no particular karma that stands out as habitual, the most likely single karma to cause rebirth is karma performed at the moment of death, for example getting angry or upset, crying or clinging to something, or listening to the dhamma or meditating.
kattata-kamma (merely performed karma) - finally, the last karma to lead to rebirth is some karma that comes to mind at the moment of death, even at random.
Of course, besides the first of the four, one's state of mind at the moment of death can potentially nullify all karma and even lead one to not be reborn again. The point is that, regardless of what colours it, it is that last moment that leads to rebirth (or nibbana).
This is exemplified by the interesting story of Queen Mallika (Dhp-A 151), who was a devoted Buddhist who performed great acts of charity and morality, but died remembering a single act of deception towards her husband and therefore went to hell. After spending seven days in hell, she died again and was reborn in heaven due to her good deeds. Perhaps this also suggests that one's rebirth itself isn't as important as one's karma, since it will all generally work its way out in the end.