The Gunners had been knocked out of the last Champions League qualification spot by north London rivals Tottenham Hotspur earlier on Sunday after they beat Leicester City.
But Mikel Arteta's side responded to the pressure with a third consecutive victory to give them the edge in what has become a two-horse race for fourth place.
After a cagey opening to the contest in which Arsenal enjoyed most of the possession without posing any real danger, Rob Holding gave the visitors the lead with a glancing header from a 38th-minute corner swung in by Bukayo Saka.
It was Holding's first Premier League goal but it was not enough to secure a halftime lead as on the stroke of the interval Jarrod Bowen controlled Vladimir Coufal's ball into the area and his shot took a deflection to beat Aaron Ramsdale who moments earlier had saved well from Declan Rice.
Arsenal looked fresher in the second half though and Gabriel's diving header from Gabriel Martinelli's delivery ensured they remained in the driving seat for a long-awaited return to the Champions League although, with a north London derby still to come, the race is far from over.
Arsenal have 63 points from 34 games with Tottenham on 61 points, also with four games left to play.
"You have to find a way to win and today we won ugly. We have to recognise that is the way we had done it," said Arteta, who is trying to deliver Champions League football for the first time since 2016-17.
"We showed incredible spirit. We adapted. You have to find a way to win, all the time to win – forcing mistakes, being brilliant, digging in, clean sheets."
Seventh-placed West Ham are now out of the running for fourth place with 52 points and only three games left and their focus will turn to next week's second leg of their Europa League semifinal against Eintracht Frankfurt.