Since the early 1800s, the literal meaning of “upset” has been to overturn something or knock it over. That’s still what it means to upset an inanimate object. Some translations of the New Testament, for example, say that Jesus “went into the Temple and upset the tables of the money-changers,” that is, pushed them over.
From there, it developed several metaphorical senses. Phrases like “upset the apple cart,” or “upset the boat” mean to cause trouble or throw everything into chaos. Almost immediately after it became a synonym for “knock over,” we see people using “upset” as an adjective to mean a person was in distress. Today, though, it means that someone is worried or angry. Another sense of the word that’s stayed closer to the literal meaning is “an upset stomach,” a feeling of nausea as if you were on a boat that had turned over.
A more formal example is, “Nationalism in the 1800s upset the balance of power in Europe ....” or “In her best work the solution completely upset the traditions of traditional mysteries.“ These both connote a challenge that shakes up the established order, which might be a holdover from an even earlier meaning of the word. Back in the 1400s, an upset was an insurrection. (That meaning of the word is no longer used.) This sense is used of abstract nouns, not concrete objects or people.
The meaning you’re asking about is related to these other meanings. As others have brought up, an upset in sports is a victory that surprises everybody. Metaphorically, it’s overturning the table of results or creating a serious challenge to the top team. In this sense, it can be used in several different ways: “The underdog upset the favorite,” “The result was a major upset,” or as you correctly used it, “an upset victory.”