Biologist Neal J. Smatresk--Dean of the College of Science at the University of Texas at Arlington--offers this explanation:
Caffeine--the drug that gives coffee and cola its kick--has a number of physiological effects. At the cellular level, caffeine blocks the action of a chemical called phosphodiesterase (PDE). Inside cells, PDE normally breaks down the second chemical messenger cyclic adenosine monophosphate (cAMP). Many hormones and neurotransmitters cannot cross the cell membrane, and so they exert their actions indirectly via such second messengers; when they bind to a receptor on the surface of a cell, it initiates a chemical chain reaction called an enzyme cascade that results in the formation of second messenger chemicals.
Historically, cAMP was the first second messenger ever described. Now, however, scientists have identified several major classes of second messengers, which are generally formed in similar ways through a set of molecules called G proteins. The advantage of such a complex system is that an extracellular signal can be greatly amplified in the process, and so have a massive intracellular effect.
Thus, when caffeine stops the breakdown of cAMP, its effects are prolonged, and the response throughout the body is effectively amplified. In the heart, this response prompts norepinephrine--also called noradrenalin--and a related neurotransmitter, epinephrine, to increase the rate and force of the muscle's contractions. Although the two act in concert, norepinephrine is released by sympathetic nerves near the pacemaker tissue of the heart, whereas epinephrine is released primarily by the adrenal glands. These chemical messages lead to "fight or flight" behavior. During stressful or emergency conditions, they raise the rate and force of the heart, thereby increasing the blood pressure and delivering more oxygen to the brain and other tissues.
Caffeine would be expected to have this effect on any animals that used these neurotransmitters to regulate their heartbeat. Generally speaking, the effects of caffeine are most pronounced in birds and mammals. Reptiles have some response, and lower vertebrates and invertebrates have rather small or no responses. From an evolutionary perspective, fish and amphibians don't show as strong a response to epinephrine and norepinephrine as the higher vertebrates, and they lack a well-developed sympathetic (that is, stimulatory) enervation to heart.