Yojimbo

In 1860, during the final years of the Tokugawa shogunate,[a] a rÅnin (masterless samurai) wanders through a desolate Japanese countryside. While stopping at a farmhouse, he overhears an elderly couple lamenting that their only son has given up farm labouring in order to run off and join the rogues who have descended on a nearby town that has become divided by a gang war. The stranger heads to the town where he meets the owner of a small Izakaya who advises him to leave. He tells the rÅnin that the two warring clans are led by Ushitora and Seibei. The silk merchant and mayor back Seibei while the sake brewer is allied with Ushitora. But after sizing up the situation, the stranger says he intends to stay as the town would be better off with both sides dead.
He first convinces the weaker Seibei to hire him as a swordsman by effortlessly killing three of Ushitora's men. When asked his name, he sees a mulberry field and states his name is æ¡çä¸åé Kuwabatake Sanjuro (æ¡ç Kuwabatake = mulberry field). Although ä¸åé Sanjuro is a proper given name (and therefore could very well be the rÅnin's true name), when spoken out loud it can also be interpreted as ä¸åè Sanjuro (note the different last kanji è), which means "thirty years old" (ä¸å sanju = thirty, è ro = years old)). Aware of this double meaning (and that those he's speaking to know that he used Kuwabatake as a pseudo-surname), he slyly quips: "Though I'm closer to forty, actually".
Seibei decides that with the ronin's swordsmanship (a service acquired with a large payment in ryÅ) the time is right to fight Ushitora. But Sanjuro eavesdrops on Seibei's wife who orders her son to kill him after the upcoming raid so that they will not have to pay his fee. Sanjuro leads his faction to attack the other but then "resigns" leaving Seibei to his fate. But before the two side clash, the untimely arrival of a BugyÅ (an Edo official) forces both sides to make a bloodless retreat.
Eventually the BugyÅ is called away because a government official was murdered in another town. Sanjuro soon learns it was two assassins hired by Ushitora who committed the killing in order to get the official to leave. With this knowledge, Sanjuro captures the pair of killers and sells them to Seibei. But he then tells Ushitora that it was Seibei's men who caught them. An alarmed Ushitora rewards him for his help. Ushitora then orders the kidnapping of Seibei's son who he offers in exchange for the two prisoners. However, Ushitora double crosses Seibei at the swap when his brother, Unosuke, shoots the assassins with a pistol. But Seibei anticipated this so he kidnapped Ushitora's woman. The next morning she is swapped with Seibei's son.
Sanjuro learns that the woman is the wife of a local farmer who lost her to Ushitora over a gambling debt, who then gave her away as chattel to the town's powerful residents in order to gain their support. Sanjuro tells Ushitora that Seibei is on the way to kidnap her from her secret hideaway. While Ushitora rallies his men, Sanjuro kills all six guards. He then reunites the woman with her husband and young son and tells them to leave town. However, Unosuke becomes suspicious of Sanjuro and the ransacked building. Eventually Sanjuro is severely beaten after Unosuke discovers evidence of his double cross.
But Sanjuro manages to escape when Ushitora decides to eliminate Seibei once and for all. As he is being carried out of town in a coffin by the izakaya owner, he witnesses the brutal end to Seibei, his family and his clan. Sanjuro recuperates in a cemetery. However, when he learns that the man who helped him has been taken by Ushitora, he returns to the town. Sanjuro manages to kill Ushitora and his men as well as Unosuke who fires wildly with his pistol. He only spares one terrified young man who he encountered on his way into town. Sanjuro then departs knowing that his task has been accomplished.

Question: What forces the two sides to make a bloodless retreat before they can clash?
Answer: the untimely arrival of a Bugy; the untimely arrival of a Bugy