Match ends, Germany 0, Brazil 1.
Germany lost for the first time in 23 matches as Manchester City forward Gabriel Jesus scored the only goal to give Brazil the win in Berlin.
This was the first full meeting between the two nations since Germany humiliated Brazil 7-1 in the 2014 World Cup semi-final in Belo Horizonte.
Jesus put Brazil ahead with a powerful diving header late in the first half.
He missed another chance with a header and Germany's Julian Draxler had a late shot tipped over as Brazil held on.
It meant Joachim Low's side, the reigning world champions and the team top of the world rankings, lost for the first time since a 2-0 defeat by France in the semi-finals of Euro 2016.
Since then, they had won 16 times and drawn six before this match at the Olympiastadion.
A small measure of revenge for Brazil
Although it was only a friendly, this win will mean a lot to a Brazilian side that has been haunted by their failure to win the World Cup almost four years ago in their own country and the humiliating nature of their exit at the hands of Germany.
Before the match, Brazil coach Tite, who was appointed boss in 2016, said: "This has a huge psychological meaning - no-one needs to fool themselves about that.
"The 7-1 is like a ghost, people still talk about it. The more you talk about it, the less this ghost disappears. The wound is still open and the match in Berlin is a part of the process of closing it."
Tite backed up his words by naming what looked to be the strongest side that he had available, with only Neymar absent as he recovers from a fractured metatarsal.
Germany, on the other hand, made six changes from the side that drew 1-1 with Spain on Friday and made five substitutions during the match, compared to only one by Brazil.
The visitors went ahead in the 37th minute when Jesus' powerful diving header was fumbled over the line by third-choice goalkeeper Kevin Trapp.
That had come only seconds after Jesus had missed a chance by shooting over and he was wasteful again in the second half, heading wide with the goal unguarded after Trapp had come off his line and misjudged a corner.
However, the German did redeem himself with a fine diving save to deny ex-Tottenham man Paulinho's well-struck effort.
Manchester City pair Leroy Sane and Ilkay Gundogan failed to make an impact for the hosts, and both were substituted.
Germany finally produced a shot on target in the 92nd minute, with Brazil goalkeeper Alisson pushing over Draxler's effort.
Brazil beat Germany in the 2016 Olympic Games football final, but this was the first senior international between the sides since 2014 and Brazil's victory helped them ease the wounds from four years ago.
'This jersey deserves a little more respect'
Brazil defender Thiago Silva, who was suspended for the 2014 game, said: "It was a matter of pride, after all that has been written and said.
"This jersey deserves a little more respect. That's why I'm overjoyed about winning against a big opponent."
Germany boss Joachim Low: "It was to be expected that Brazil, with their injured soul, played their best team and were highly motivated.
"It wasn't our day. We made too many mistakes, which allowed Brazil to grow in strength and confidence.
"We had a few young players who will learn from this, but in addition, the body language was not right from some players."
- 17BoatengSubstituted forSüleat 68'minutes
- 21GündoganSubstituted forWernerat 81'minutes
- 24GoretzkaSubstituted forBrandtat 61'minutes
- 19SanéSubstituted forStindlat 61'minutes
- 23GomezSubstituted forWagnerat 62'minutes
- 22ter Stegen
- 2Alves da Silva
- 14Thiago Silva
- 9Gabriel Jesus
- 11CoutinhoSubstituted forDouglas Costaat 73'minutes
- 4Coquette Russo
- 6dos Santos
- 7Douglas Costa
- 8Renato Augusto
- 16Murara Neto
- 25Da Silva
- Jonas Eriksson
- Shots on Target
Second Half ends, Germany 0, Brazil 1.
Corner, Germany. Conceded by Willian.
Corner, Germany. Conceded by Alisson.
Attempt saved. Julian Draxler (Germany) right footed shot from outside the box is saved in the top centre of the goal. Assisted by Toni Kroos with a cross.
Corner, Germany. Conceded by Marcelo.
Offside, Brazil. Fernandinho tries a through ball, but Gabriel Jesus is caught offside.
Attempt missed. Joshua Kimmich (Germany) right footed shot from outside the box misses to the left.
Corner, Germany. Conceded by Thiago Silva.
Julian Brandt (Germany) wins a free kick in the defensive half.
Foul by Douglas Costa (Brazil).
Attempt blocked. Dani Alves (Brazil) right footed shot from outside the box is blocked.
Attempt missed. Julian Draxler (Germany) left footed shot from a difficult angle on the left misses to the left. Assisted by Julian Brandt with a cross.
Attempt missed. Sandro Wagner (Germany) header from the centre of the box misses to the right. Assisted by Julian Draxler with a cross following a corner.
Corner, Germany. Conceded by Thiago Silva.
Attempt blocked. Julian Brandt (Germany) left footed shot from outside the box is blocked. Assisted by Joshua Kimmich.
Attempt saved. Paulinho (Brazil) right footed shot from outside the box is saved in the bottom left corner. Assisted by Douglas Costa.
Corner, Brazil. Conceded by Toni Kroos.
Substitution, Germany. Timo Werner replaces Ilkay Gündogan.
Attempt missed. Lars Stindl (Germany) right footed shot from outside the box is too high. Assisted by Toni Kroos.