Ecuador, with eight regulars from their World Cup team, went ahead early in Stockholm through Felix Borja but then had Luis Antonio Valencia sent off in the 29th minute.
Brazil, who began with playmaker Ronaldinho on the bench, levelled when Fred pounced on a defensive blunder in the 44th minute.
The former world champions extended their unbeaten run to four matches under new coach Dunga, who replaced Carlos Alberto Parreira after their disappointing campaign in Germany.
"We're definitely on the right track and this match confirms it," Dunga told reporters. "We played good opposition here.
"The most important thing is to create a great squad. It's not all about the 11 players on the field."
Kaka wasted an early chance for Brazil when he shot weakly at Cristian Mora before Robinho had another effort comfortably stopped by the goalkeeper.
But Ecuador looked confident and went ahead in the 23rd minute.
Edison Mendez produced an inswinging cross from the right and striker Borja, known as the Kangaroo, lived up to his nickname as he leapt to head the ball past Gomes.
RED CARD
As the tackles flew in, Wigan Athletic's Valencia was shown the red card.
Dudu Cearense put his arm around Valencia's throat as the pair tussled for the ball, the Ecuadorian elbowed him in the chest and the Brazilian went down clutching his face.
Robinho scraped the post for Brazil with a dipping shot before Fred equalised, firing home from 12 metres after Giovanny Espinoza sent a dreadful clearance straight to him.
Ronaldinho replaced defensive midfielder Cearense at halftime and Brazil took control.
Ecuador defended valiantly until Kaka, having blasted a shot against the bar, made it 2-1 by sweeping home Ronaldinho's cross from 12 metres in the 74th minute.
Ronaldinho, without an international goal since last year's Confederations Cup, twice hit the crossbar from free kicks in the closing minutes.
Ecuador coach Luiz Fernando Suarez said: "The sending off changed everything. Before it we were doing everything right, then it became difficult.
"We had hoped to play a better match for the crowd but the sending off forced us back. But the result and the sending off were fair."
(Writing by Brian Homewood in Rio de Janeiro)