RIO DE JANEIRO — An Olympic gold medal in soccer for Brazil will not undo the embarrassment of the 2014 World Cup. Perhaps nothing will. But Saturday provided a dramatic recovery, a tense rekindling of joy where before there was national shame.

Maracanã Stadium filled with celebration and relief as Brazil won its first Olympic soccer title, defeating Germany, 5-4, on penalty kicks after the match remained tied at 1-1 through 120 minutes. The victory provided some redemption from, if not erasure of, a humiliating 7-1 defeat to Die Mannschaft at home in the semifinals of the World Cup.

When the Brazilian goalkeeper Weverton dived to his left to save a penalty kick by Germany’s Nils Petersen, the anxiety of the evening exploded into liberation.