Answer by taking a quote from the following article:

Charles V (Spanish: Carlos; German: Karl; Italian: Carlo; Latin: Carolus; Dutch: Karel; French: Charles,  24 February 1500 - 21 September 1558) was ruler of both the Spanish Empire as Charles I from 1516 and the Holy Roman Empire as Charles V from 1519, as well as of the lands of the former Duchy of Burgundy from 1506. He stepped down from these and other positions by a series of abdications between 1554 and 1556. Through inheritance, he brought together under his rule extensive territories in western, central, and southern Europe, and the Spanish viceroyalties in the Americas and Asia.

Charles fought continually with the Ottoman Empire and its sultan, Suleiman the Magnificent. The defeat of Hungary at the Battle of Mohacs in 1526 "sent a wave of terror over Europe." The Muslim advance in Central Europe was halted at the Siege of Vienna in 1529.  Suleiman won the contest for mastery of the Mediterranean, in spite of Spanish victories such as the conquest of Tunis in 1535. The regular Ottoman fleet came to dominate the Eastern Mediterranean after its victories at Preveza in 1538 and Djerba in 1560 (shortly after Charles's death), which severely decimated the Spanish marine arm. At the same time, the Muslim Barbary corsairs, acting under the general authority and supervision of the sultan, regularly devastated the Spanish and Italian coasts, crippling Spanish trade and chipping at the foundations of Habsburg power.  In 1536 Francis I of France allied himself with Suleiman against Charles. While Francis was persuaded to sign a peace treaty in 1538, he again allied himself with the Ottomans in 1542 in a Franco-Ottoman alliance. In 1543 Charles allied himself with Henry VIII and forced Francis to sign the Truce of Crepy-en-Laonnois. Later, in 1547, Charles signed a humiliating treaty with the Ottomans to gain himself some respite from the huge expenses of their war.  Charles V made overtures to the Safavid Empire to open a second front against the Ottomans, in an attempt at creating a Habsburg-Persian alliance. Contacts were positive, but rendered difficult by enormous distances. In effect, however, the Safavids did enter in conflict with the Ottoman Empire in the Ottoman-Safavid War, forcing it to split its military resources.

Who  did Charles defeat to gain the Roman emperor title?
Charles fought continually with the Ottoman Empire and its sultan, Suleiman the Magnificent.