Trailing 2-1 entering the seventh, Prince Fielder led off with a double and came home with the tying run when Delmon Young sent a grounder up the middle for a hit, chasing Pittsburgh starter Kevin Correia (1-5).
The rally made a winner of Max Scherzer (3-3), who fanned 15 batters over seven innings, surrendering a pair of runs on four hits.
Joaquin Benoit logged his first save despite allowing a run in the ninth for Detroit, which took the rubber match of a three-game weekend interleague series.
Correia ended up yielding three runs on four hits over six full frames.
Barajas homered and drove in two runs while Neil Walker also went deep in the Bucs' loss.