The Habsburgs were successful because they produced heirs and formed political alliances through marriage across Europe. Their dominance over Europe and their colonial possessions in America gave rise to the (often recycled) phrase: "the sun never sets on the [Habsburg] Spanish empire."
The Bourbons were a cadet branch of the ruling Capetian dynasty that ascended the French throne in 1589 (under Henry IV). They produced heirs and remained enthroned until the French Revolution (1791), only to be restored after the defeat of Napoleon, and then later replaced by the cadet Orleans branch in 1830, which was itself removed in 1848.
The Bourbons ascended to the throne of Spain in 1700 under Philip V, after the Habsburg King Charles II died without issue. Philip was the grandson of Charles' half-sister, Maria Theresa, and the Sun King, Louis XIV. Although his elder brother (Louis XV) was in line to the French throne, Philip's ascension to the Spanish throne was conditional on his renouncement of the French crown so as to avoid a personal union between France and Spain. Disputes over the succession led to the War of the Spanish Succession (1701 - 1714) between The Grand Alliance (the Habsburgs, Great Britain, the Dutch Republic and later others) and the Bourbons. The conflict was settled by the signing of the Treaty of Utrecht, which affirmed the renouncement of his claim to the French throne.
The ongoing rivalry between both powerful houses spilled over into war from time to time. Apart from the War of the Spanish Succession, there were the Italian Wars, the Thirty Years' War, and the Nine Years' War. In general, these wars sought to check each other's power. There were also strategic marriages between the Houses during pauses in enmity. The three most notable examples were in 1615 (Anne of Austria to Louis XIII), 1660 (Maria Theresa to Louis XIV) and 1770 (Maria Antonia to Louis XVI).
An addition to the question, if I may: Maybe this question could be expanded to cover not just the Habsburg and the Bourbon dynasties, but the Habsburgs and the Capetians (including their cadet branches)?