When things go wrong.... there is usually a reason why.... do some soul-searching and try to work out why this particular thing happened and what Hashem is trying to tell you.
And they said to one another, "Indeed, we are guilty for our brother, that we witnessed the distress of his soul when he begged us, and we did not listen. That is why this trouble has come upon us." [Miketz 42:21]
The brothers realized immediately that when misfortune befalls a person, he must search his deeds to find a negative word or action that may have brought on such a punishment. Then he should do teshuvah.
The brothers' teshuvah was remarkable in that:
1) They were able to feel remorseful about a bad deed they performed some twenty years earlier.
2) The fact that they could not find a more recent sin to explain their current misfortune shows that in the past twenty years they did not sin at all.
3) Their teshuvah was immediately effective in reducing the punishment: Yosef had promised to imprison one of the brothers, but after the brothers did teshuvah, Shimon was released [see Rashi to v.24]. Similarly, Yosef's harsh attitude towards them changed, for they were given food and their money was returned. And eventually, as a result of their teshuvah, Yaakov and their entire family were saved from hunger.
Source: Based on Sicha of the fifth day of Chanukah: Lubavitcher Rebbe