First, know that this happens to every traveller and long-term expat without exception, and locals almost everywhere hold foreigners to a gentler standard than each other; what they read is not the mistake but your response to it.
The response that works across cultures: stop the offending behaviour immediately, apologise simply and sincerely, without a defensive explanation of how things work back home, and let your body language carry the regret, whether a hand over the heart, a slight bow, or just an evidently genuine expression. The local word for sorry, even badly pronounced, does disproportionate work. Then move on without excessive drama; in face-saving cultures especially, prolonging the apology or making a scene of your own embarrassment can compound the awkwardness, since it forces everyone to keep managing the moment. A light touch of self-deprecating humility, acknowledging you are still learning, lands well nearly everywhere.
Afterwards, do two things: quietly ask a local friend or colleague what exactly went wrong so it never repeats, which itself signals respect, and if the offence was toward a host or someone you will see again, a small follow-up gesture such as a note or modest gift completes the repair in most cultures. If you accidentally broke an actual law, cooperate calmly with officials and handle it through proper channels rather than argument.