In 2014, I entered the US in January as a tourist had the I94 valid until July; I overstayed (until December) for 5 months more than I was allowed. I tried to return this week, almost 4 years later, got denied entry and sent back to Brazil the next day. Is there any way to reverse the denial? What could I do to return legally, after I violated the terms on my earlier visa?
No, there is no avenue for appeal or option to "reverse" a decision. The fact is, you overstayed; you cannot change that. Your only option is to apply for a new visa, demonstrating very strong ties to your home country, and hope that they approve it. If they don't, there is nothing else you can do.