Ajam (عجم) in Arabic means non-Arabic-speaker. Ajam is an Arabicized word that came from Jam or jamshid the name of a A Persian legendary king or prophet ,according to old stories he was the king  able to fly  around the world by a throne or Carpet.

in most of the languages  Ajam and Ajami means Persian. in Arabic Ajam means someone whose mother tongue is not Arabic. The early use of the term included all of the peoples with whom the Arabs had contact including Persians, Greeks, Ethiopians, and the somewhat related Nabataeans.

Etymology
In general, during the Umayyad period Ajam was a pejorative term used by Arabs who believed in their social and political superiority, in early history after Islam. 
According to the book "Documents on the Persian Gulf's name ", pages 22–44 explanation of Ajam and the Persians "The word Ajam has many different uses and meanings throughout the history. words had a simple meaning at first, but over the time, other meanings and concepts are added to its early meaning, especially when the word goes to other languages. Ajam was first used for Persian native speaking in the poems of the Arab poet of pre Islam  but after expansion of Islam it also was referred to Turks,Zoroastrianism and others. Today, in Arabic literature, "Ajam" is used to refer to the non-Arab person. Ajam has never meant dumb in Arabic literature , using The word Ajam as a derogatory meaning was very late and very rare and unofficial concept in Umayyad period time. 
according to the new finding "Ajam infact had a root in the persian word  Jam Jamshid The stories of "Jam and Jamshed and the word Molouk Ajam (Persian emperor) were well known to the Arabs before Islam and the word Molouk Ajam (Ajam kings) and Molk e Ajam(persia) were used in poems of famous 7 Arab poets of Jahiliyyah (pre Islam). one of the famous Arab figures Nadr ibn al-Harith wrote a book about the stories of the Molouk of Ajam (persian kings)Rustam Naqsh-e Rustam and Jamshid and Fereydun and presented it to the new Muslims and said that my book is more important than the stories of Muhammad.  Al-A'sha another  famous  Arabic Jahiliyyah (pre Islam) poet from ArabiaNajd, had wrote poems describing Ajam/Persian king(Molouk Ajam) one of the  Al-A'sha poem is:" أَوْ عَاتِقًا مِنْ أَذْرُعَاتٍ مُعَتَّقًا مِمَّا تَعَتَّقَهُ مُلُوكُ الأَعْجَمِ For the first time in the Umayyad period, the derogatory use of the word Ajam applied to the Persians. but during Abbasid and after  The word Ajam was used for the Persians not only for humiliating but also a source of pride, as some Arabs even in The pre-Islamic period proudly narrated the glorious stories of the Molouk(kings) of Ajam and the Molk of Jam (Persia).the Arab poets Yaqut al-Hamawi  and Al-Mutawakkil wrote: "I am the son of the honors Offspring of Jam(jamshid) holder of the glory legacy of Persian kings.انا ابن المکارم من النسل جم و حائز ارث ملوک العجم 

according to the Documents on the Persian Gulf's name it is very natural that in Arabicizing the words sometimes A is added to the words like Asfehan Isfahan in Arabic from the word Persian word SEPAHAN .
during the period Iranian Intermezzo native Persian Muslim dynasties the word ajam and persian both were used to refer to Iranian.
Many Arabic sources refer to Persian language as Ajami language or Ajmo. Persian is the official language in Iran as "Parsi" and "Farsi", in Afghanistan as Parsi and Dari,  and Tajiki  in Tajikistan, Persian in Bahrain is called "Ajami" and in Kuwait "Ayami" . In classical Arabic, especially in the first centuries of the Islamic period, the Persian language was called "the language of the Ajam" لسان العجم, and the Iranian people were called the "Ajami" and the persian gulf was called Ajam Gulf, in many books and deed,  Tafsir al-Zahak The oldest commentary on Quran wrote on page 524 " In Surah An-Nahl, verse 103,the word Ajami refers to Salman Farsi and says Ajami is the Persians.  .also Arabic word for dictionary is mo'jam (moajam) that means definition of the non Arabs(ajam) word.
According to The Political Language of Islam, during the Islamic Golden Age, 'Ajam' was used colloquially as a reference to denote those whom Arabs in the Arabian Peninsula viewed as "alien" or outsiders. The early application of the term included all of the non-Arab peoples with whom the Arabs had contact including Persians, Byzantine Greeks, Ethiopians, Armenians, Assyrians, Mandaeans, Arameans, Jews, Georgians, Sabians, Samaritans, Egyptians, and Berbers.

During the early age of the Caliphates, Ajam was often synonymous with "foreigner" or "stranger".  In the Western Asia, it was generally applied to the Persians, while in al-Andalus it referred to speakers of Romance languages - becoming "Aljamiado" in Spanish in reference to Arabic-script writing of those languages - and in West Africa refers to the Ajami script or the writing of local languages such as Hausa and Fulani in the Arabic alphabet.  In Zanzibar ajami and ajamo means Persian which came from the Persian Gulf and the cities of Shiraz and Siraf. In Turkish, there are many documents and letters that used Ajam to refer to Persian. 
In the Persian Gulf region and also the Turks people still refer to Persians as Ajami, referring to Persian carpets as sajjad al Ajami (Ajami carpet), Persian cat as Ajami cats, and Persian Kings as Ajami kings.

Notable examples
The Persian community in Bahrain is called Ajami.
Ajam was used by the Ottomans to refer to the Safavid dynasty.
The Abbasid Iraq Al-Ajam province (centered around Arax and Shirvan).
The Kurdish historian, Sharaf Khan Bidlisi, uses the term Ajam in his book Sharafnama (1597 CE) to refer to the Shia Persians. 
In the Eastern Anatolia Region, Azerbaijanis are sometimes referred to as acem (which is the Turkish translation of Ajam).
Although claimed otherwise by Mahmood Reza Ghods, Modern Sunni Kurds of Iran do not use this term to denote Persians, Azeris and Southern Kurds. According to Sharhzad Mojab,  Ecem (derived from the Arabic ‘ajam) is used by Kurds to refer to Persians and, sometimes, Turks.
Adjam, Hajjam, Ajaim, Ajami, Akham (as Axam in Spain for ajam), Ayam in Europe.
In Turkish, the word acem refers to Iran and Iranian people.
It is also used as a surname.
In Arab music, there is a maqam (musical mode) called Ajam, pejoratively translated to "the Persian mode", corresponding to the major scale in European music.

Related pages
Barbarian - which came to refer to people who spoke neither Greek nor other "civilized" languages (such as Latin), and derived from a root meaning "speaking incomprehensibly" or "babbling"

References

Arabic words and phrases
Ethnic and religious slurs
Persian communities outside Iran
Anti-Iranian sentiments
Racism in the Arab world