Sheffield Wednesday kept alive their hopes of automatic promotion from League One, while ending Brentford's slim play-off chances at the same time.
Wednesday took the lead through Keith Treacy - who found the net with a free kick from just outside the area.
Stephen Bywater pulled off a fine save from Clayton Donaldson, before the same player levelled from the penalty spot.
But the visitors grabbed all three points with Miguel Angel Llera flicking home Treacy's cross.
The result means Wednesday, who have one game left this season, are two points ahead of Sheffield United in third, although their city rivals have two matches to play.
VIEWS FROM THE DRESSING ROOM
Brentford manager Uwe Rosler told BBC London 94.9:
"It shows how far we have come to be outplaying Sheffield Wednesday in all areas.
"We are still missing that little bit of quality to get it over the line to win against one of the big teams.
"We have come a long way and I am very proud of my players.
"We need a little bit more belief and a little bit more consistency and maybe a little bit of experience and then we will be very very close."
Sheffield Wednesday manager Dave Jones told BBC Radio Sheffield:
"We needed the win and I wasn't coming here to just pick up a point. My objective was to try and get three.
"The game was going to be a little bit more open than we would have liked, but that's because we were chasing the game to win it.
"We rode our luck a bit, but that's the sign of a good team.
"That's sometimes what you have to do, it's not about your performance all the time, it's about getting results."
Sorry, we were unable to load match stats, please try again.