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."
Live Text Commentary
Full Time The final whistle goes and the game is over.90:00 +2:45
Direct free kick taken by Simon Moore.90:00 +2:45 Booking
Booking Lewis Buxton receives a caution for unsporting behaviour.90:00 +2:31
Lewis Buxton concedes a free kick for a foul on Sam Saunders.90:00 +1:24
Jonathan Douglas produces a right-footed shot from inside the area that clears the bar.89:28
Daniel Jones fouled by Marcus Bean, the ref awards a free kick. Direct free kick taken by Chris Lines.87:58
Chris Lines decides to take a short corner.87:02
Niall McGinn takes a shot. Save by Stephen Bywater.86:09
Outswinging corner taken by Chris Lines, save by Simon Moore.84:09
The assistant referee flags for offside against Gary Madine. Simon Moore takes the free kick.82:55
Nile Ranger is caught offside. Harlee Dean takes the indirect free kick.80:30 Substitution
Substitution Chris O'Grady joins the action as a substitute, replacing Keith Treacy.80:30
Corner taken right-footed by Sam Saunders, Karleigh Osborne takes a shot from inside the six-yard box clearing the crossbar.80:30 Substitution
Substitution Marcus Bean replaces Pim Balkestein.80:30 Substitution
Substitution Shaleum Logan leaves the field to be replaced by Luke Norris.80:30
Toumani Diagouraga takes a shot. Save by Stephen Bywater.79:46
Keith Treacy is caught offside. Simon Moore restarts play with the free kick.78:17
Jermaine Johnson takes a shot. Blocked by Karleigh Osborne. Inswinging corner taken left-footed by Keith Treacy from the right by-line, clearance by Pim Balkestein. Inswinging corner taken from the left by-line by Chris Lines.75:35
Free kick awarded for an unfair challenge on Clayton Donaldson by Danny Batth. Sam Saunders crosses the ball from the free kick right-footed from left wing.74:13 Substitution
Substitution Niall McGinn joins the action as a substitute, replacing Harry Forrester.
Gary Madine gives away a free kick for an unfair challenge on Pim Balkestein. Free kick taken by Harlee Dean.67:57 Substitution
Substitution Jermaine Johnson joins the action as a substitute, replacing Michail Antonio.66:54
Jose Vitor Semedo concedes a free kick for a foul on Sam Saunders. Free kick crossed right-footed by Sam Saunders.65:44
Keith Treacy provided the assist for the goal.65:44 Goal scored
Goal! - Miguel Angel Llera - Brentford 1 - 2 Sheff Wed Miguel Angel Llera finds the back of the net with a goal from close range to the bottom left corner of the goal. Brentford 1-2 Sheff Wed.64:22
Chris Lines restarts play with the free kick. Keith Treacy takes the inswinging corner,64:22 Substitution
Substitution (Sheff Wed) makes a substitution, with Daniel Jones coming on for Mark Beevers.64:22
Mark Beevers fouled by Harry Forrester, the ref awards a free kick.62:32
Mark Beevers challenges Harry Forrester unfairly and gives away a free kick. Free kick crossed right-footed by Shaleum Logan, Stephen Bywater makes a save.61:57 Goal scored
Goal! - Clayton Donaldson - Brentford 1 - 1 Sheff Wed Placed penalty scored by Clayton Donaldson. Brentford 1-1 Sheff Wed.60:14
Mark Beevers gives away a Penalty for an unfair challenge on Clayton Donaldson.59:31
Nile Ranger is caught offside. Indirect free kick taken by Simon Moore.57:22
Free kick crossed right-footed by Sam Saunders, Chris Lines manages to make a clearance.57:22 Booking
Booking Miguel Angel Llera is shown a yellow card.57:05
Clayton Donaldson fouled by Miguel Angel Llera, the ref awards a free kick.56:03
Foul by Jose Vitor Semedo on Jonathan Douglas, free kick awarded. Jonathan Douglas takes the free kick.54:07
Inswinging corner taken from the right by-line by Keith Treacy.53:26
Clayton Donaldson takes a shot. Save by Stephen Bywater. Sam Saunders takes the outswinging corner, clearance by Miguel Angel Llera.49:11
Free kick awarded for an unfair challenge on Jose Vitor Semedo by Harry Forrester. Chris Lines crosses the ball in from the free kick, Pim Balkestein makes a clearance. Inswinging corner taken by Chris Lines, save by Simon Moore.46:53
Inswinging corner taken left-footed by Keith Treacy from the right by-line to the near post, clearance by Jonathan Douglas.46:29
Sam Saunders takes a shot. Stephen Bywater makes a save.45:01
The referee gets the second half started.45:00 +2:20 Half time
Half Time The referee calls an end to the first half.44:55
Clayton Donaldson is caught offside. Stephen Bywater takes the indirect free kick.42:14
Pim Balkestein produces a right-footed shot from outside the penalty area and misses left.40:12
Clayton Donaldson takes a shot. Stephen Bywater makes a save.37:33 Goal scored
Goal! - Keith Treacy - Brentford 0 - 1 Sheff Wed Keith Treacy grabs a goal direct from the free kick from just outside the box to the bottom right corner of the goal. Brentford 0-1 Sheff Wed.36:46
Free kick awarded for a foul by Pim Balkestein on Michail Antonio.36:01
Jonathan Douglas takes a shot.33:16
Free kick awarded for a foul by Harry Forrester on Mark Beevers. Direct free kick taken by Miguel Angel Llera.32:21
Miguel Angel Llera takes the direct free kick.32:21 Booking
Booking Jonathan Douglas is cautioned.32:09
Jonathan Douglas concedes a free kick for a foul on Jose Vitor Semedo.31:30
Foul by Harlee Dean on Gary Madine, free kick awarded. Free kick taken by Miguel Angel Llera.30:54
Effort from the edge of the penalty box by Sam Saunders goes wide of the right-hand upright.28:13
Clayton Donaldson challenges Keith Treacy unfairly and gives away a free kick. Miguel Angel Llera restarts play with the free kick.26:51
Free kick taken by Sam Saunders. Jake Bidwell takes a shot. Save by Stephen Bywater.26:51 Booking
Booking Caution for Mark Beevers.26:24
Mark Beevers challenges Harry Forrester unfairly and gives away a free kick.25:34
Unfair challenge on Clayton Donaldson by Miguel Angel Llera results in a free kick. Shaleum Logan takes the free kick.23:17
Harlee Dean challenges Gary Madine unfairly and gives away a free kick. Direct free kick taken by Lewis Buxton.21:06
Harry Forrester takes a shot. Save by Stephen Bywater.20:15
Free kick awarded for an unfair challenge on Jake Bidwell by Lewis Buxton. Free kick crossed right-footed by Sam Saunders from left by-line, Chris Lines manages to make a clearance.19:49
Foul by Gary Madine on Shaleum Logan, free kick awarded. Shaleum Logan takes the direct free kick.18:53
Shot by Keith Treacy from outside the box goes over the net.17:28
Harlee Dean gives away a free kick for an unfair challenge on Nile Ranger. Chris Lines crosses the ball from the free kick right-footed from right channel, Toumani Diagouraga manages to make a clearance. Free kick awarded for an unfair challenge on Toumani Diagouraga by Nile Ranger. Simon Moore takes the free kick.14:59
Shaleum Logan takes a long range shot harmlessly clearing the crossbar.12:15
Effort on goal by Clayton Donaldson from just inside the area clears the crossbar.11:05
Karleigh Osborne takes a shot. Save by Stephen Bywater.9:00
Michail Antonio challenges Toumani Diagouraga unfairly and gives away a free kick. Simon Moore takes the direct free kick.7:18
Foul by Harry Forrester on Keith Treacy, free kick awarded. Danny Batth takes the free kick. Effort from just outside the box by Lewis Buxton goes over the bar.6:33
Nile Ranger challenges Sam Saunders unfairly and gives away a free kick. Sam Saunders takes the direct free kick.5:16
Shot from just outside the penalty area by Jonathan Douglas misses to the left of the target.2:51
Unfair challenge on Harry Forrester by Jose Vitor Semedo results in a free kick. Direct free kick taken by Karleigh Osborne.0:13
Sam Saunders concedes a free kick for a foul on Chris Lines. Centre by Keith Treacy, Miguel Angel Llera takes a shot. Save made by Simon Moore.0:00
The referee starts the match.
Live data and text provided by our data suppliers