Languages usually have two sets of names that for the ease of explanation, I refer to them as internal name and external name. An internal name (endonym, local name) is the name used by its native speakers and external names (exonym, foreign name) are what the speakers of other languages use to call it. For example, Germans call their language Deutsch but it is known as German in English, as allemand in French and as tedesco in Italian. "Deutsch" is the internal name. "German", "allemand" and "tedesco" are some of the external names for "Deutsch".
The same is true of Persian. Its internal name is Farsi but it is known as Persian in English, as persan in French, as persiano in Italian, as Farsça in Turkish, etc. In recent decades, many Persian speakers have immigrated to Western countries. Many of them do not know their language has "external" names in the western part of the world and simply use "Farsi", the name that is natural to them.
Using "Farsi" is not always due to ignorance but I do not discuss about it here because whether it is unintentional or otherwise, the point stands: saying, for example, "I learn Farsi" is like saying "I learn Deutsch". That is not how these languages have been called in English and are known to English speakers. "Farsi" does not connote any historical or cultural background. In English, it is "Persian" Magi, "Persian" carpet, "Persian" cat, … and of course, "Persian" language.
Iran is also the "internal" name of the country. It was known in the West as Persia since ancient times until 1935, when King Reza Pahlavi officially asked the international community to adopt "Iran". In contrast, the Academy of Persian Language and Literature has delivered a pronouncement on the name of the Persian language, rejecting any use of the word "Farsi" in foreign languages.
Offical Variants of Persian
Persian has official status in Iran, Afghanistan and Tajikistan. Thanks to its long and rich literary heritage, written Persian and its literary form in particular, is the same in all Persian-speaking countries. Tajiks and Afghans cherish the works of Ferdowsi, Rumi, Hafez, … just as Iranians do. We are historically and culturally one nation.
English is not spoken the same everywhere. Persian has also many dialects, including three official ones. Official variants of a language are conventionally named by territory. We say American English, Canadian French, Swiss German, Brazilian Portuguese, Mexican Spanish and so on. Following the same norm, official variants of Persian are: Iranian Persian, Afghan Persian and Tajik Persian.
This universal naming convention is not completely received (mainly for political reasons). Native speakers refer to their language as "Persian", but officials call it Dari in Afghanistan and Tajik in Tajikistan. There is no mention of "Persian" in these names. As though what they speak in Afghanistan and Tajikistan is not Persian.
Dari is a historical attribute and is not exclusively applicable to the varieties of Persian in Afghanistan. Its use dates back to the ninth century, when both Middle Persian and New Persian coexisted. Middle Persian was locally called Pahlavi and New Persian was called Dari. That is to say, all modern forms of Persian are counted "Dari", and not just Afghan Persian.
Since 1939, when Tajikistan was under Soviet rule, Tajik Persian is written in Cyrillic alphabet. It is not unprecedented for Persian to be simultaneously written in more than one alphabet. Jewish dialects of Persian are written in Hebrew alphabet. As another example, Persian was written in more than four alphabets during Sasanian Empire.