Ajax took a shock 2-0 half-time lead as both Thulani Serero and Danny Hoesen netted their first European goals.
Xavi scored a penalty after Joel Veltman was sent off but Ajax withstood fierce pressure in the remainder of the second half.
With AC Milan beating Celtic in the other game in the group, the result was vital for Ajax and they now face the Italians in their final game with the winners reaching the knockout stages.
The losers of that game will play in the Europa League, with Celtic eliminated from Europe with a game to spare.
Ajax midfielder Lasse Schone was booked for an early foul on Neymar but soon made a more positive impact, setting up fellow Dane Viktor Fischer for a volley which was saved by Jose Pinto.
The keeper could do nothing in the 19th minute, though, when Ricardo van Rhijn's cross picked out the well-timed run of Serero, who arrived unmarked 10 yards out to sidefoot home the opener.
Fischer sent another volley over the bar and Schone curled an effort just wide before Barca finally threatened through Neymar. The Brazilian shimmied past two defenders but saw his shot deflected wide.
Gerard Pique was booked for a foul on Ajax captain Nicolai Boilesen, who had to be replaced by midfielder Christian Poulsen with Daley Blind moving to left-back.
Cesc Fabregas was booked for dissent six minutes before half-time, ruling him out of Barca's final group game against Celtic.
And three minutes later, Ajax took a 2-0 lead as Fischer seized on defensive uncertainty and when his shot was blocked by Pinto, Hoesen followed up to score.
Things took a turn Barcelona's way just three minutes into the second half though. Van Rhijn's under-hit back-pass forced last man Veltman to bring down Neymar and, after the right-back was sent off, Xavi converted from 12 yards.
Neymar was booked after his attempted bicycle kick caught Van Rhijn in the head, and he then tried a lob which the back-pedalling Jasper Cillessen tipped over.
Barca substitute Patric Gabarron volleyed wide and their frustration mounted in the closing stages. Pedro's penalty appeal was dismissed and Neymar was denied by an offside flag as somehow Ajax stood firm.