"Rabbi Yossi Haglilee used to say: One who is involved in a mitzvah is exempt from another mitzvah" (Sukkah 26a). A mitzvah is entitled to one's full attention[1], and our Sages long ago understood that when one tries to multi-task, both tasks will end up the poorer for the effort. Despite the inherent logic involved in such reasoning, the Talmud looks for scriptural support for this notion. One might have argued that we should never give up the opportunity to do another mitzvah--and two non-optimal mitzvoth are better than one given our full attention[2].
The Gemara cites two different sources for this exemption (Sukkah 25a-b). The first is derived from the wording of the Shema. We are commanded to recite such b'shivetecha bveitecha uv'lechtecha baderech, "when you sit in your house and when you walk in your way" indicating an obligation to recite it only if one is involved with one's own works, but not if busy with the work of heaven--i.e., another mitzvah. Thus, to cite the gemara's example, a bridegroom[3] is exempted from this mitzvah on his wedding night[4].The second source is derived from those who were tameh met, who had attended to a dead body in the seven days prior to Pesach, thereby precluding themselves from participating in the mitzvah of korban pesach[5].
The gemara explains that we need both of these sources. The derivation from Pesach teaches that we need not be concerned about the neglected mitzvah even if under normal circumstances it carries the penalty of karet, excision, as does the failure to bring a korban pesach where possible. The source from the Shema teaches that even though the obligation to recite Shema preceded the wedding, the mitzvah of getting married exempts one from the mitzvah to recite the Shema.
By using the example of a bridegroom, the gemara teaches that this exemption applies not only to a mitzvah that requires physical toil and effort, but even when one is investing only mental effort into a mitzvah. The thoughts of a bridegroom are elsewhere, and that is good enough to trigger an exemption.
The other example cited by the Talmud to elucidate this principle is that of a mourner. One who is an onen, who is preparing to bury a relative, is forbidden[6] to observe any positive mitzvoth. However, once the deceased is buried, the mourner is actually obligated in all mitzvoth with the exception of tefillin. While his thoughts may be elsewhere, our tradition insists that a mourner slowly but surely return to a regular routine.
Despite--or precisely because of--the opposing emotions brought about by marriage and death, the high and low points of life, it is these two mitzvoth that take precedence over all others. Even participating in a funeral exempts one from prayer and the recital of the Shema (Brachot 17b). One must first attend to the needs of others--both in joy and distress--before turning to G-d in prayer[7].
[1] Tosafot (25a, s.v. Sheluchai mitzvah) notes the obvious. One is only exempt if the mitzvah requires effort, such as feeding your animal (that is the Tosafists' example); but if one is effortlessly fulfilling a mitzvah (what a great concept!) such as wearing tzizit, one may not invoke this principle.
[2] Authorities debate if involvement in one mitzvah forbids one from doing another mitzvah or merely exempts one from such. If the latter, then the Torah gives us the choice whether we want to focus on one mitzvah or try and do two mitzvoth simultaneously.
[3] While it is highly recommended that she do so, women are exempt from the recital of Shema, as it is a time-bound positive mitzvah from which women are exempt. Thus, the Talmudic discussion focuses on a bridegroom.
[4] Tosafot (Brachot 17b, s.v. Rav Sisha) notes that in our days, even a bridegroom is to recite Shema on his wedding night. The exemption assumes that one will be unable to concentrate on the yoke of heaven that night. Since in our day, we don't have such focus on any night, to pretend that one's wedding night is special in this regard would be deemed yuhara, religious arrogance. Don't you love the openness and honesty of our Sages?
[5] Little did they know that their request for a chance to bring a korban pesach would be honored, with their request being the springboard for Pesach Sheni (see Bamidbar 9:1-8).
[6] Some authorities do allow an onen to do mitzvoth if funeral arrangements have been made, as the onen is no longer involved in another mitzvah. This is not the accepted view, as it is both an unreasonable demand and inappropriate behavior to observe mitzvoth with a relative awaiting burial.
[7] I have never understood the basis--and thus refuse to join-- the minyanim that often take place in the middle of a wedding. That is the time to bring joy to a bride and groom, not to call out to G-d.