Meanings
To get a controlling power over someone/something

Examples
Strong winds made it impossible for the firefighters to get the upper hand on the huge forest fire, and hundreds of forest acres burned down
I forti venti hanno impedito ai vigili del fuoco di prendere il sopravvento sull'incendio che ha poi bruciato centinaia di ettari di bosco

In the last World War, the allied forces got the upper hand on the enemy
Nell'ultima guerra mondiale le forze alleate presero il sopravvento sul nemico

The cowboy tired the wild horse so that he finally got the whip hand and tamed it
Il cowboy ha sfiancato il cavallo selvaggio tanto da riuscire a prendere il sopravvento e domarlo

In the second half of the match the home team got the upper hand over the opponents and won hands down
Nel secondo tempo dell'incontro la squadra di casa ha preso il sopravvento sulla squadra avversaria e ha poi vinto a mani basse

Origin
This phrase originated with the advent of sandlot baseball. In order to determine which team would bat first, one player would grasp the baseball bat at the lower end. A player from the opposing team would then place his hand directly above the first player's hand. They would alternate hands up the bat until the end was reached and one of the players had the "upper hand"