In 1860, during the final years of the Edo period and the demise 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 Gonji, 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. Ushitora was the right-hand man of Seibei but rebelled when Seibei decided to hand over the reins to his son Yoichiro, a useless youth. The town's mayor and its silk merchant, Tazaemon, had long been in Seibei's pocket, and Ushitora aligned himself with the sake brewer, Tokuemon, proclaiming him the new mayor. 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.
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 sides clash, the untimely arrival of a bugyō (an Edo-period government 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 murder 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, Nui, 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 influential sake brewer, Tokuemon, in order to gain his support. Sanjuro tricks Ushitora into revealing the place where Nui is hidden, then kills the guards and reunites the woman with her husband and son and tells them to leave town immediately. Pretending to be on Ushitora's side, Sanjuro is able to convince Ushitora that the woman was kidnapped by Seibei's men. A new spike in violence occurs in the gang war, Tazaemon's silk warehouse is burned down by Ushitora, and Tokuemon's sake brewery is trashed by Seibei in retaliation. After some time, Unosuke becomes suspicious of Sanjuro and the circumstances surrounding Nui's escape. Eventually Sanjuro is severely beaten and imprisoned by Ushitora's thugs after Unosuke discovers evidence of his double cross.
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 Gonji, the izakaya owner, he witnesses the brutal end to Seibei, his family and his clan. Sanjuro recuperates in a small temple near 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, even though he is armed with a pistol. He only spares one terrified young man who he encountered on his way into town. As Sanjuro surveys the damage, Tazaemon comes out of his home, in samurai outfit and beating a prayer drum. Tazaemon circles around town and then goes after and kills Tokuemon. Sanjuro frees Gonji and then departs, knowing that his task has been accomplished.