Short Answer
Yes. Christian knights fought for Muslim rulers as mercenaries, the best known example being El Cid. They also fought with Muslim rulers as allies. This happened both before the crusades to the Holy Land began (in 1096) and during the crusading period to the Holy Land in the 12th and 13th centuries.
Details
There are a number of references to West European mercenaries serving in various Muslim armies, but in most cases it is unclear whether any of them were knights rather than just regular soldiers. The earliest example may date as far back as the late 8th / early 9th century:
The Umayyad emir of Cordoba al-Hakam I (796–822) may have been the
first Muslim ruler to have recruited Christians into his army.
Source: Simon Barton, 'Traitors to the Faith? Christian Mercenaries in al-Andalus and the Maghreb, c.1100–1300'. In Roger Collins and Anthony Goodman (eds), 'Medieval Spain: Culture, Conflict, and Coexistence' (2002)
Prior to the 1080s, contacts between Christians and Muslims across the 'borders' that divided them were common. Then,
The creation, from the 1080s onwards, of a militarized frontier zone to the south of the Duero...may have served to discourage intimate cross-border dealings
of the kind that had prevailed in the tenth century. Likewise, the diffusion of
the ideology of crusade, not only encouraged a more expansionary mood on
the Christian side, and provided arms-bearers with spiritual as well as
material incentives to take the fight to Islam, but may also have made
Christian–Muslim alliances of the type that had proliferated in the tenth or
eleventh centuries far less palatable than hitherto.
Source: Barton
El Cid (c.1043-1099), a noble who was probably knighted by King Ferdinand I of Leon), is the best known example of a Christian fighting for a Muslim ruler:
The Spanish hero El Cid, having served as a mercenary captain for both
Christian and Muslim leaders....
Source: Hunt Janin & Ursula Carlson
The Wikipedia page on El Cid gives more details on this:
El Cid found work fighting for the Muslim rulers of Zaragoza, whom he defended from their traditional enemies, Aragon and Barcelona.
El Cid may have been involved in the Battle of Graus (1063) at which 300 Castilian knights fought on the side of Ahmad al-Muqtadir, ruler of the Islamic taifa of Zaragoza, against the Christian Ramiro I of Aragon. However, it is unclear if they were there as mercenaries or as allies.
Also in Spain, M. Florian in History of the Moors of Spain recounts the following (author's orginal spellings retained):
...in a battle which occurred A.D. 1010 between two Mussulman leaders, there were found among the slain a count of Urgel and three bishops of Catalonia...
Christian soldiers (unclear if this reference includes knights) serving a Muslim ruler prior to the Crusades is also mentioned by Hussein Fancy in The Mercenary Mediterranean
The use of Iberian Christian soldiers in Islamic armies was not
limited to the peninsula. The Almoravid ruler ‘Ali B. Yusuf Tashfin
(r. 1061 – 1106) was said to have first introduced the practice to
North Africa.
It may seem strange that Christian soldiers (knights or otherwise) at times fought for and with Muslim rulers, but we should be careful not to look at relationships between Christians and Muslims from the modern perspective. Although it is true that Christian soldiers were usually used when Muslim rulers were fighting each other rather than fighting Christians, the early spread of Islam into Christian lands was often welcomed as a relief from Byzantine rule for Muslim rulers tended to be tolerant. As Jane Smith notes:
Military expeditions were political in nature and not undertaken for the purpose of forcing conversion to Islam. Christians and Jews were given “dhimmi” status, paying a poll tax for their protection.
Further west, the ability of Muslims, Christians and Jews to live together in peace up to the 10th century is well-illustrated by Spain:
Certain periods in world history reflected harmonious interactions among the three Abrahamic faiths. Medieval Andalusia, for example, provided a venue for Muslims and Christians, along with Jews, to live in proximity and even mutual appreciation. It was a time of great opulence and achievement, and social intercourse at the upper levels was easy. It was also a period during which a number of Christians chose to convert to Islam. Medieval Andalusia has often been cited as an ideal place and time of interfaith harmony.
This did not continue, of course, but even so extremism was not prevalent at the time and in-fighting among both Christian and Muslim rulers was very common. In such cases, rulers looking for mercenaries were not necessarily going to be fussy about the religion of those they hired. Also, when the Normans became a power in southern Italy, it was at the expense of both Christian and Muslim rulers.
In fact, there was no guarantee even that a Christian ruler could trust a fellow Christian not to join forces with a Muslim army - note the career of Roussel of Bailleul whose treachery (first abandoning a Byzantine army to join a Muslim force in defeating his former ally and then later setting up an independent state) eventually led to his capture by the Seljuks and execution by the Byzantines (1077).
There are many of the examples are after the start of First Crusade (1096). One good example of Christian knights serving a Muslim ruler is this one
European mercenaries served in Muslim armies, notably in North Africa
and in the Middle east. For some years before 1147, there was a
company of Christian knights in Morocco who had their own clergy and
even a bishop. Christian mercenaries became one of the best fighting
forces in the Turkish army.
Source: Hunt Janin & Ursula Carlson, 'Mercenaries in Medieval and Renaissance Europe'
In Spain, following a papal warning in 1214 about Christians serving Muslim rulers, Archbishop Rodrigo Jiménez of Toledo, specifically addressing knights, wrote in a letter:
Since, as we have been informed, some of you on your own, others with
lords and friends, abandoning their people and native land, have
allied themselves with the Saracens, in order, if possible, to attack
and defeat the Christian people with them, we beseech and warn you all
in the Lord to desist from this aim, at such a dangerous time, and not
to ally yourselves with that perverse people; rather, as athletes of
Christ and defenders of His name and the Catholic faith, set
yourselves like a wall for the house of Israel, for the laws of the
country, and for the people and the country, ready to die, if
necessary.
Cited in Barton
In the letter, there was also what appears to be an acknowledgement that some Christians might have aided Muslim rulers because they had possibly been wronged by Christian rulers:
If by chance the king has wronged one of you in some way, so that one
might deservedly have complaint about him, he should present his
complaint at court before us and, trusting in the Lord and expecting
the discretion and generosity of the King, we will see that justice is
done to him, according to the custom of the court.
Cited in Barton
On a final note, the Romance of Gillion de Trazegnies, a medieval work of fiction, concerns a knight who commanded the sultan of Egypt’s army. Although fiction, the character is based on various knights of the period so there may well be some factual basis.
(all emphasis is mine)
Other sources:
C. M. Yonge The Story of the Christians and Moors of Spain
S. Lane-Poole The Moors in Spain
Brian Todd Carey Warfare in the Medieval World
S. Runciman A History of the Crusades: vol 1