Yojimbo was inspired by Dashiell Hammett’s ‘The Glass Key’ which was serialized in Black Mask magazine in 1930 and published as a novel the following year.
And Hammett’s Red Harvest for that matter.