The job title everyone gets slightly wrong
Anubis is usually introduced as "the Egyptian god of death": jackal head, black skin, the figure standing over mummies in tomb paintings. That description is close enough to pass in casual conversation, and wrong enough to matter if you look closely. In the mythology most people learn, the actual ruler of the underworld, the one who presides over it the way Hades presides over the Greek underworld, is Osiris. Anubis's canonical later job description is narrower: god of mummification and funerary rites, guardian of tombs, guide of souls into the afterlife, and officiant of the ceremony that decides whether a soul is admitted at all. He manages the process. Osiris sits in judgment over the outcome.
That division of labor looks tidy in a textbook, and it is also relatively recent by Egyptian standards. For a long stretch of Egyptian history before that arrangement existed, Anubis was not Osiris's funerary director. He was the only one with the job, and Osiris had not yet shown up in the written record at all.
Older than Osiris, at least in writing
A jackal god, generally identified as Anubis, appears on royal tomb inscriptions from the First Dynasty, in the reigns of pharaohs Hor-Aha and Djer, roughly 3150 to 2890 BC. That puts him among the oldest attested gods in Egyptian religion, present at the very start of the written record.
Osiris is not. According to the Egyptologist Harold M. Hays, cited on Wikipedia's entry for the god Khenti-Amentiu, the offering formula used to sustain the dead in the afterlife originally invoked only Anubis's name. Other gods, Osiris among them, do not join that formula until the Fifth Dynasty, roughly 2494 to 2345 BC, and Osiris's name "does not appear in any texts before the start of the dynasty." There is a real gap between the two gods in the historical record, not a small one, and Anubis is on the older side of it by a margin of centuries.
The oldest surviving body of Egyptian religious writing, the Pyramid Texts, was carved into the interior burial chamber of the pyramid built at Saqqara for Unas, the last king of that same Fifth Dynasty, around 2350 BC. That is a different building from the Great Pyramid of Giza, raised roughly a century and a half earlier for Khufu, which carries no inscriptions of this kind at all; the practice of lining pyramid walls with spells starts with Unas. Anubis appears directly inside it. Utterance 213, inscribed on the south wall of the sarcophagus chamber, addresses the dead king's body part by part: "Your lower arms are of Atum, your upper arms of Atum... your face of Anubis." That is an odd, almost architectural way to describe a face, built by assembling the king out of gods rather than describing what he looks like, and Anubis is one of the pieces used to build him.
How Osiris got the promotion
Once Osiris's name enters the record, his cult grows fast, and it grows specifically into Anubis's territory. By the Middle Kingdom, roughly 2055 to 1650 BC, Osiris had become ruler of the underworld and the figure Egyptians looked to for judgment after death. At Abydos, an old cult center where a local jackal god named Khenti-Amentiu, "foremost of the westerners," had stood guard over the dead since before Egypt's unification, the temple was explicitly rededicated to Osiris starting in the First Intermediate Period, around 2181 to 2055 BC. The title itself, once loosely shared between Anubis and the local Abydos jackal, became fixed to Osiris instead.
Anubis did not disappear. He was folded into Osiris's own myth as a subordinate with a specific, gruesome job: when Osiris is murdered and dismembered by his brother Set, Anubis is the one credited with reassembling and embalming the body, performing the first mummification in Egyptian myth on the god who would go on to outrank him. The Opening of the Mouth ritual, meant to restore a mummified person's senses in the afterlife, is tied to this same embalming role. A god who once stood alone at the top of Egyptian funerary religion ended up, in the mature version of the myth, working on the corpse of his own replacement.
The weighing of the heart, and who is actually in charge
The clearest picture of Anubis's demoted role comes from the Papyrus of Ani, a copy of the Book of the Dead made around 1300 BC and now held at the British Museum. It shows the scribe Ani and his wife Tutu brought before an assembly of gods, where Anubis leads Ani forward and weighs his heart on a set of golden scales against the feather of Ma'at, goddess of truth and order. The monster Ammit, part crocodile, part lion, part hippopotamus, waits beside the scale to devour any heart too heavy with wrongdoing to balance. Thoth, the ibis-headed god of writing, records the result. Osiris sits enthroned at the far end of the scene, the one the verdict is ultimately delivered to. The Greeks personified truth too, as Aletheia, the goddess of truth, whom a Roman fable left without feet.
Every figure in that composition has a function, and Anubis's is procedural rather than judicial: he operates the scale, he does not decide what the reading means. That is the demotion in miniature, rendered on a single sheet of papyrus. The god who used to be the whole afterlife bureaucracy became its most visible administrator, working in front of a boss who did not exist when his own job started.
Family trouble that never got settled
Anubis's parentage shifts depending on which century of Egyptian religion you ask. In Old Kingdom sources he is a son of the sun god Ra. In the Coffin Texts of the First Intermediate Period he shows up as the child of the cow goddess Hesat, or alternately Bastet, or Ra and Nephthys together. By the Middle and New Kingdoms the standard version makes him son of Osiris and Isis outright, folding him neatly into the family he now serves.
The Greek writer Plutarch, in his essay De Iside et Osiride ("Isis and Osiris"), written around the turn of the second century AD, gives a messier account that has nothing to do with tidy family trees. In the translation by Frank Cole Babbitt, Plutarch says Isis learned that Osiris had slept with her sister Nephthys "through ignorance, in the belief that she was Isis," and found proof in a garland of melilote flowers he had left behind. Nephthys, afraid of her husband Set (whom Plutarch calls by his Greek name, Typhon), abandoned the child at birth. Isis searched for him "with the help of dogs which led Isis to it," and once found, he "was brought up and became her guardian and attendant, receiving the name of Anubis, and it is said to protect the gods just as dogs protect men." Even in that version, born from an affair and raised by an aunt who was not his mother, Anubis's story does not read as a scandal so much as an origin for a job: guard dog, literally and administratively, to the family that displaced him.
Egyptian myth was never bothered by that kind of inconsistency the way a modern reader might expect. Athena springs fully grown from Zeus's head in one Greek tradition with no mother involved at all, and nobody in that mythology treated the odd birth as a plot hole either. A shifting genealogy was normal wherever a religion developed over centuries across different regional cult centers instead of being fixed once by a single author.
An oath the Greeks borrowed
Anubis's reach went beyond Egypt's own borders. In Plato's dialogue Gorgias, Socrates swears twice by a canine god, in W.R.M. Lamb's translation for the Loeb Classical Library: first simply "by the Dog" (461b), while still addressing Gorgias directly near the end of their exchange, then in fuller form, "by the Dog, god of the Egyptians" (482b), once the argument has moved on to his next interlocutor, Callicles. Ancient commentators read the oath as a reference to Anubis, invoked as a guarantor of truth in an Athenian philosophical argument that has nothing to do with Egyptian religion otherwise. A jackal-headed foreign god had become, for a Greek philosopher a continent away, shorthand for swearing an honest oath.
Centuries later, under Roman rule, Egyptian and Greek religion fused Anubis directly with Hermes, the Greek psychopomp god who also guided souls, producing a hybrid sometimes called Hermanubis. A marble statue from Anzio, now in the Vatican Museums and dated to the first or second century AD, shows the result: Anubis with a jackal's head, dressed in a Roman toga, holding a sistrum in one hand and, in the other, a caduceus, the staff that belongs to Hermes rather than to any Egyptian god. It makes for an odd hybrid object, and also a record of staying power. Within Egypt, Anubis had already lost his original job to Osiris more than a thousand years earlier. Outside Egypt, people were still building new statues of him and lending him another god's staff to make sure he stayed recognizable.
A god's earliest recorded rank rarely matches the one history remembers him for. Poseidon turns up as the most frequently named deity in the Bronze Age palace archive at Pylos, centuries before Greek epic settled him into second place behind Zeus. Anubis ran the opposite direction, from sole lord of the dead to Osiris's embalmer and gatekeeper, and still came out the more durable image. He remained, across the whole span of ancient Egyptian art, one of the most frequently depicted gods in the entire religion, even after the promotion went to someone else.