According to hadith, if a person is sincere, their repentance can be accepted until the time they see the Angel of Death; or, if they were committing wrong out of ignorance, until the soul leaves the throat. (These times are given in different narrations; perhaps they are reflecting a similar time for the person about to pass on.) However, if they were intentionally doing wrong and expecting to be able to repent for it at the last minute, this option will not be there for them (nor would their repentance be sincere).
This is the idea being Qur'an 4:18 - that people cannot persist in wrongdoing and then expect to get out of it at the last minute. Rather, once they realize they are doing wrong, they should try to make a change.