There are two driving forces behind chemical reactions. First, molecular systems move to minimize potential energy. This is usually achieved by forming bonds (covalent bonds, ionic bonds, hydrogen bonds, van der Waals interactions, etc). Second, molecular systems want to maximize their disorder (entropy). Often, breaking bonds will lead to an increase in the entropy of a system.
Thus, in many cases, molecular systems are pushed in opposite directions by these competing goals. Let's take a simple example of ice melting/water freezing. Ice consists of a highly ordered lattice of water molecules that are optimally hydrogen bonded. Because ice is so ordered, it has a very low entropy. Therefore, by the second criterion above, ice would like to melt into liquid water which has much less order and therefore much more entropy. However, in liquid water, water molecules have on average fewer hydrogen bonds than in ice. Because these hydrogen bonds stabilize water molecules and lower their potential energy, the first criterion above would seem to favor the formation of ice in order to minimize the water molecules' potential energy.
What happens to the system depends on the balance between minimizing potential energy versus maximizing entropy. If the system favors minimizing potential energy over maximizing entropy, ice should be favored over liquid water. On the other hand, if maximizing entropy is favored over minimizing potential energy, liquid water should be favored over ice.
The factor that sets this balance between these two opposing goals is temperature. At high temperatures, the system is more concerned with maximizing entropy than minimizing potential energy, and at low temperatures, the opposite situation is favored. Therefore, water freezes at low temperatures and melts at high temperatures and not the other way around.