It boils down to thermodynamics. No, molecules do not possess intelligence. But they respect the laws of thermodynamics, which in a general look state:
- Energy of a closed system is constant.
- The entropy of the universe is always increasing.
- You can't get to absolute zero temperature! (Ok, this one is less important for this analysis)
The second law is the key: in order to augment the entropy of the universe a certain transformation can do one of two things: increase its own entropy or the entropy of its surroundings. The latter can be achieved by releasing heat, which is something exothermic reactions do. The sum of these effects is described by the system's Gibbs free energy:
$$G = H - TS$$
For a chemical reaction occurring at a constant temperature and pressure, $G$ has to decrease and becomes minimized at equilibrium. We then say the system is (thermodynamically) "stable". So when you hear someone say "chemical reactions minimize their energy", it would be better spoken as "... minimize their free energy".
Now you might wonder why the second law is true. Why does entropy has to increase? Why does the free energy has to be minimized? It certainly doesn't want to.
The truth lies in the molecular interpretation of entropy: it measures the amount of micro-states at which system can be found. Put together a bunch of blue balls with another bunch of red balls in a box, shake it all and look at how they end up. They surely won't be found in separate sides of the box, they will mix! The scenario where they are separated corresponds to a very low-entropy state: you can think of the red ones to one side or vice-versa: not that many possibilities of arrangements. The mixed state though has a much higher entropy: think of how many arrangements are possible by exchanging the positions of red and blue balls!
Since molecules in a closed system are very very much like tiny balls being shaken inside a box - not by a mechanical source but by their own thermal energy -, their behavior with respect to entropy is the same. Again, it's not that they want to increase the entropy of universe, there just is a higher probability that they do rather than don't. Given that we are usually observing systems of sextillion molecules or more, statistics kicks in and tell us probabilities mean more or less certainty: we are pretty much certain that chemical reactions will keep on trying to maximize the entropy of the universe.