By the fourth century, Arab tribes began to encroach from Yemen, and there were three prominent Jewish tribes that inhabited the city into the 7th century AD: the Banu Qaynuqa, the Banu Qurayza, and Banu Nadir. Ibn Khordadbeh later reported that during the Persian Empire's domination in Hejaz, the Banu Qurayza served as tax collectors for the shah.
The situation changed after the arrival from Yemen of two new Arab tribes named Banu Aus (or Banu 'Aws) and Banu Khazraj. At first, these tribes were allied with Jewish rulers, but later they revolted and became independent. Toward the end of the 5th century, the Jewish rulers lost control of the city to Banu Aus and Banu Khazraj. The Jewish Encyclopedia states that "by calling in outside assistance and treacherously massacring at a banquet the principal Jews", Banu Aus and Banu Khazraj finally gained the upper hand at Medina.
Most modern historians accept the claim of the Muslim sources that after the revolt, the Jewish tribes became clients of the Aus and the Khazraj. However, according to scholar of Islam William Montgomery Watt, the clientship of the Jewish tribes is not borne out by the historical accounts of the period prior to 627, and he maintained that the Jewish populace retained a measure of political independence.
Early Muslim chronicler Ibn Ishaq tells of a pre-Islamic conflict between the last Yemenite king of the Himyarite Kingdom and the residents of Yathrib. When the king was passing by the oasis, the residents killed his son, and the Yemenite ruler threatened to exterminate the people and cut down the palms. According to Ibn Ishaq, he was stopped from doing so by two rabbis from the Banu Qurayza tribe, who implored the king to spare the oasis because it was the place "to which a prophet of the Quraysh would migrate in time to come, and it would be his home and resting-place."
The Yemenite king thus did not destroy the town and converted to Judaism. He took the rabbis with him, and in Mecca, they reportedly recognized the Ka'ba as a temple built by Abraham and advised the king "to do what the people of Mecca did: to circumambulate the temple, to venerate and honour it, to shave his head and to behave with all humility until he had left its precincts." On approaching Yemen, tells ibn Ishaq, the rabbis demonstrated to the local people a miracle by coming out of a fire unscathed and the Yemenites accepted Judaism.
Eventually the Banu Aus and the Banu Khazraj became hostile to each other and by the time of Muhammad's Hijra (emigration) to Medina in 622 AD/1 AH, they had been fighting for 120 years and were the sworn enemies of each other. The Banu Nadir and the Banu Qurayza were allied with the Aus, while the Banu Qaynuqa sided with the Khazraj. They fought a total of four wars.
Their last and bloodiest battle was the Battle of Bu'ath that was fought a few years before the arrival of Muhammad. The outcome of the battle was inconclusive, and the feud continued. Abd-Allah ibn Ubayy, one Khazraj chief, had refused to take part in the battle, which earned him a reputation for equity and peacefulness. Until the arrival of Muhammad, he was the most respected inhabitant of Yathrib. To solve the ongoing feud, concerned residents of the city met secretly with Muhammad in Al-Aqaba, a place betweeh Makkah and Mina, inviting him and his small band of believers to come to Yathrib, where Muhammad could serve as disinterested mediator between the factions and his community could practice its faith freely.
In 622 AD/1 AH, Muhammad and around 70 Meccan Muhajirun believers left Mecca for sanctuary in Yathrib, an event that transformed the religious and political landscape of the city completely; the longstanding enmity between the Aus and Khazraj tribes was dampened as many of the two Arab tribes and some local Jews embraced Islam. Muhammad, linked to the Khazraj through his great-grandmother, was agreed on as civic leader. The Muslim converts native to Yathrib of whatever background—pagan Arab or Jewish—were called Ansar ("the Patrons" or "the Helpers").
According to Ibn Ishaq, the local pagan Arab tribes, the Muslim Muhajirun from Mecca, the local Muslims (Ansar), and the Jewish population of the area signed an agreement, the Constitution of Medina, which committed all parties to mutual cooperation under the leadership of Muhammad. The nature of this document as recorded by Ibn Ishaq and transmitted by Ibn Hisham is the subject of dispute among modern Western historians, many of whom maintain that this "treaty" is possibly a collage of different agreements, oral rather than written, of different dates, and that it is not clear exactly when they were made. Other scholars, however, both Western and Muslim, argue that the text of the agreement—whether a single document originally or several—is possibly one of the oldest Islamic texts we possess.
(source)