Mainz went ahead through Andreas Ivanschitz in the 27th minute, but Bastos levelled four minutes before the break.
Zdenek Pospech restored the hosts' lead midway through the second half, but Bastos ensured the visitors a draw with eight minutes left.
Schalke have now one just once in their last 11 Bundesliga matches to sit two points behind their opponents.
Mainz had the first chance of the game in the sixth minute, but Schalke keeper Timo Hildebrand made a superb reflex save to keep out Nikolce Noveski's header from six yards and Benedikt Howedes cleared away the loose ball.
Schalke then went close, but Raffael's attempt from a Bastos cross went over the bar.
Mainz took the lead a minute later as Nicolai Muller danced past three Schalke defenders on the right wing and crossed for Ivanschitz to fire home first time from 15 yards.
Schalke equalised in the 41st minute when Mainz keeper Christian Wetklo stopped Jermaine Jones' shot, but Raffael ran on to the loose ball and crossed for Bastos to slot home from five yards.
Wetklo made a great save in the 54th minute, saving a Julian Draxler shot from six yards out.
And Mainz reclaimed the lead after 63 minutes on the counter attack as Ivanschitz played the ball into the path of Pospech, who blasted it into the far left corner for his first Bundesliga goal.
Mainz missed a chance to double their lead when Elkin Soto's shot went inches wide of the far post.
Instead, Schalke equalised again with eight minutes to play, Max Meyer playing the ball across to Bastos, who steadied himself and struck a shot into the right corner.
And Hildebrand ensured the visitors left with a point with two fine saves in the 86th minute following shots by Chinedu Ede and Noveski.