The robbery attempt that went spectacularly wrong happened on Sunday on a highway between Mexico City and Pachuca, local media reported.
The three criminals boarded the bus in the city of Ecatepec de Morelos. Minutes later they drew their guns and told passengers to surrender their valuables.
Then one of the robbers fired his handgun to intimidate their victims. The bullet ricocheted from the bus ceiling and hit another criminal, fatally injuring him.
Some 30 passengers agitated by the gunfire rushed the two perpetrators. They beat one of them to death, subdued the other and later handed him over to the police. It was not clear whether the robber killed by the passengers was the same one who wasted his partner.
Highway robberies are a major problem in Mexico, a country that suffers badly from organized crime. People visiting the country are advised to stick to toll roads and not to travel at night to reduce the risk of being targeted.