Marquinhos had Brazil dancing on Tuesday.

The Brazilian’s tip-in with just seconds on the clock was the deciding bucket in Brazil’s 66-65 upset of Spain, the second loss in this tournament for the No. 2 ranked Spaniards.

Pau Gasol had a chance to give Spain a three-point lead from the foul line with 24 seconds remaining but missed both of his shots. That gave Brazil the chance to take the lead, and Marquinhos played the role of the hero, sneaking around the backside of the basket to tip home Marcelo Huertas’ missed floater.

Spain still had six seconds to earn the win, but Sergio Llull missed a difficult runner down the right side, and Spain couldn’t gather the rebound and get another shot off before the game ended.

Huertas (11 points, seven assists, four rebounds), Marquinhos (10 points, five rebounds) and Augusto Lima (nine points, 10 rebounds) led the way for Brazil, who stifled Spain with solid defense and a patient half-court approach. In total, 10 players scored for Brazil.

Gasol, meanwhile, led the Spaniards with a solid showing, scoring 13 points and adding 10 rebounds and four blocks. Llul (11 points) and Sergio Rodriguez (10 points, five assists) played well in support, though NBA stars such as Ricky Rubio (three points, no assists or steals) and Nikola Mirotic (six points, eight rebounds) had disappointing showings.

The Spaniards now have a heck of a battle on their hands to reach the knockout phase, with tough games against Argentina and Lithuania remaining, along with what should be a gimme against Nigeria. If Spain loses just one more game, it’ll be in real danger of being eliminated from this tournament before the quarterfinals, which would be a shock, to say the least.

Brazil’s chances of reaching the knockout phase grew considerably better with this victory, meanwhile. Croatia and Argentina still remain, but the Brazilians have proved they can hang with some of the top teams in the world.

Group B is wide-open. Spain isn’t dead, but it is on life support. Brazil isn’t safe, but it will be feeling confident after Tuesday’s huge victory.