Chon Wang is a Chinese imperial guard. After Princess Pei-Pei, for whom Wang has affection, is abducted and taken to the United States, the Emperor of China sends three of his guards to retrieve her. Wang is not among one of the three, but after he tells them that it was his fault the princess was kidnapped, he is merely sent in the hopes that the "foreign devils" would get rid of Wang. In Nevada, Roy O'Bannon is an outlaw who, with his gang, hijacks the train Wang is on. When Wallace, a member of Roy's gang, kills Wang's uncle, Wang chases the outlaws down. However, the gang is well-armed and Wang's only choice is to unhinge the cars and get away on the engine. In the process, Wallace takes over the gang from Roy, and they leave him buried up to his chin in the desert sand.
Meanwhile, Pei-Pei, who was tricked into believing she was freely escaping her arranged marriage in China, finds out she has been kidnapped by an agent of Lo Fong, who ran away from the Forbidden City and was viewed as a traitor by the Chinese. When Wang finds Roy buried in the sand, he demands to know the direction to Carson City. Roy tells him that the city is on the other side of a mountain. Wang puts two chop sticks in Roy's mouth for him to dig himself out. When Wang comes out the other side of the mountain, he gets involved with a Sioux tribe by saving a boy chased by the Crow tribe and ends up reluctantly marrying the tribe chief's daughter, Falling Leaves. Wang finds Roy in a tavern and, in anger, starts a fight with him that turns into a barroom brawl.
The two of them get sent to prison, and after Falling Leaves helps them escape, they become friends. Roy trains Wang in the ways of the cowboy. When they get to Carson City, Roy discovers that both he and Wang, now identified as the "Shanghai Kid" are wanted by Lo Fong's ally Marshal Nathan Van Cleef, and the two of them narrowly escape. They go to a bordello (which Roy describes as his "hideout"), but after a drunken encounter by Wang, the Marshal eventually catches and arrests them. They find out that Lo Fong is behind the kidnapping of the princess.
As they are about to be hanged, Wang manages to break himself free and after Falling Leaves shoots Roy loose, they escape the execution site. Wang, upset over Roy previously telling one of the prostitutes at the bordello he was not Wang's friend, rides off alone to find the Princess. However, Roy follows him and the two reunite when Roy saves him from Fong. The next day, the two partners go to the ransom point, the Carson City Mission church. The three imperial guards arrive with the gold, and Lo Fong has the princess in hand. However, a simple exchange becomes complicated when Wang shows up and Roy points a gun towards Fong. Wang tells his fellow guards that he will not allow them to bring the princess back to China. As the Chinese and Lo Fong fight amongst themselves, Van Cleef arrives and engages Roy in a gunfight.
After Roy is limited to one remaining bullet, Van Cleef simultaneous fires both of his guns but Roy shoots him in the heart. Wang fights the Imperial Guards whilst Lo Fong chases Pei-Pei through the rafters of the church. After Wang knocks all three Guards unconscious he fights Lo Fong to the bell tower. Wang ultimately kills Lo Fong by dismantling the bell causing it to hang Lo Fong.
When they awaken, the Imperial Guards decide that they will let the princess stay. Wallace and his gang also come up to the church, and demand that Roy and Wang come out and fight. But when the two of them get outside the church to face Wallace, Natives from all around surround the gang. At a Chinese cultural celebration Roy thanks Falling Leaves for saving him and they engage in a passionate kiss. At the same time, Pei-Pei holds a smiling Wang's hand.
Roy and Wang are shown as sheriffs and ride off to catch a new band of train robbers..