It seems remarkable that the Ottoman Empire was able to hold together an empire that encompassed many of the different ethnic and religious groups that are currently in conflict today (such as the Kurds, Sunnis, and Shiites, among others). How did the Ottomans manage to successfully rule such a diverse empire?
This is a big question, one which historians have been asking for decades.
My period of focus is the Early Modern (usually defined in Middle Eastern history as 1517-1798), and in that period historians most commonly emphasize the Ottoman Empire's remarkable ability to strike a balance between central and local power. Government in the Middle East revolved around the carefully managed relationship between the agents of the Ottoman state, such as provincial governors (beylerbeyi, vali), and local powerholders often referred to as 'notables' (ayan). In many regions significant power was granted to the ayan with regard to issues like taxation, and their role as middlemen between the Ottoman state and provincial society was significant for ensuring stability. You could perhaps call this a form of 'benign neglect.' If a provincial notable ever became too powerful or sought to resist the state, the Ottomans could respond by supporting his rivals, a frequent occurrence in unruly regions such as Lebanon and Kurdistan. In general, though, attempts at true independence were very rare. Most ayan recognized the value of remaining within the Ottoman system, even if they occasionally resorted to violent means in an effort to renegotiate their position vis-a-vis the Ottoman state.
The Ottomans also went to great lengths to maintain their legitimacy. Key to this was the reputation of their dynasty as the 'Servant of the Two Holy Places' (Hadımü'l-Harameyn), meaning Mecca and Medina. Each year they invested a significant amount of resources into securing the pilgrimage route. Also of prime importance was the dynasty's emphasis on providing justice to its population. Even deep into the financial crises of the seventeenth century, the Ottomans continued to provide tax breaks to villages which petitioned the government claiming to be overburdened. Peasants' complaints were taken very seriously, and investigated wherever possible. The common people generally seem to have had a great deal of faith in the Ottoman justice system, which was centrally managed in a hierarchical system centered on Istanbul. This too contributed greatly to the stability of their rule.
Naturally the exact character of Ottoman rule varied greatly from region to region, so if there's a particular place which interests you I could explain its circumstances in greater depth.
Some worthwhile studies on provincial society in the Ottoman Middle East:
This question also seems to be relying on modern stereotypes about the Middle East being a crazy mix of ungovernable groups who will never get along. This of course ignores all sorts of histories of orientalism that I won't get into...
I think it's important to keep in mind that yes, the Ottoman lands were diverse, and yes, it was quite a feat to hold them all together effectively... But European countries in this period, just for a comparative example, were hardly what we would recognize as unified, culturally similar nations. Many parts of France, for example, didn't even speak French until the 19th or even early 20th century. They were quite diverse in their own right.
I don't think it's as much about different cultures and religions as it is about effective balance of centralized and decentralized rule, as others have pointed out. Most average people living in one part of these early modern states/empires would have had little to do with other subjects living beyond their local town or region before the advent of mass literacy, print culture, conscripted armies, etc. So as long as the vertical relationship between the Ottoman state and locals could be maintained, the wide diversity of the huge Ottoman lands wouldn't have been as a big an issue.