The king of Babylon (Akkadian: šakkanakki Bābili, later also šar Bābili) was the ruler of the ancient Mesopotamian city of Babylon and its kingdom, Babylonia, which existed as an independent realm from the 19th century BC to its fall in the 6th century BC. For the majority of its existence as an independent kingdom, Babylon ruled most of southern Mesopotamia, composed of the ancient regions of Sumer and Akkad. The city experienced two major periods of ascendancy, when Babylonian kings rose to dominate large parts of the Ancient Near East: the First Babylonian Empire (or Old Babylonian Empire, c. 1894/1880–1595 BC) and the Second Babylonian Empire (or Neo-Babylonian Empire, 626–539 BC). Babylon was ruled by Hammurabi, who created the Code of Hammurabi.
Many of Babylon's kings were of foreign origin. Throughout the city's nearly two-thousand year history, it was ruled by kings of native Babylonian (Akkadian), Amorite, Armenian, Kassite, Elamite, Aramean, Assyrian, Chaldean, Persian, Greek and Parthian origin. A king's cultural and ethnic background does not appear to have been important for the Babylonian perception of kingship, the important matter instead being whether the king was capable of executing the duties traditionally ascribed to the Babylonian king: establishing peace and security, upholding justice, honouring civil rights, refraining from unlawful taxation, respecting religious traditions, constructing temples, providing gifts to the gods in the temples and maintaining cultic order. Babylonian revolts of independence during the times the city was ruled by foreign empires probably had little to do with the rulers of these empires not being Babylonians and more to do with the rulers rarely visiting Babylon and failing to partake in the city's rituals and traditions.