Back-to-back fouls for unsportsmanlike behaviour were assessed against France's Ronny Turiaf and Nicolas Batum after hard hits at the end of the game, and players from both teams had to be restrained by officials from going after each other.
"Nobody likes to lose in the quarter-final of the Olympics," Spain's Marc Gasol said.
"Everybody wants to fight for those medals. Sometimes it gets a little out of hand because emotions get involved. Nobody got hurt, that's the most important thing."
The victory put Spain into the semi-finals against Russia, who beat Lithuania 83-74 in the opening quarter-final. The defeat eliminated France.
Spain and Russia will meet on Friday with the winners advancing to the gold medal game and the losers playing for bronze on Sunday.
Gasol led Spain with 14 points, while Tony Parker and Boris Diaw scored 15 points apiece to pace France.
Defending champions the United States play Australia, and South American rivals Brazil and Argentina meet in Wednesday's later quarter-finals.
The tightly contested quarter-final between last year's EuroBasket finalists came down to the last 91 seconds with European champions Spain holding a 58-57 lead as both teams struggled to score.
"For sure it was a different game now we're in the quarter-finals," said Spain's Sergio Rodriguez. "We played some great hard defence and so did France. We came off three games where we played really badly and really upped our game."
Diaw also said that the stakes heightened the intensity.
"It got up a level," Diaw said. "It's the quarter-finals of the Olympics. You expect that. We played well, we really gave our all. But we just couldn't make it."
The bad blood between the teams heated up when some observers believed Spain had not given a full effort in their final preliminary round loss against Brazil in order to fall into the bracket with France and avoid a potential semi-finals game against the powerhouse U.S. team.
Only 11 points combined were scored over the first eight and a half minutes of the last quarter, and then the action on court turned ugly.
Spain edged further ahead on two free throws by Rudy Fernandez after he was sent crashing on a foul by Batum.
Gasol flipped a left-handed shot in off the glass from under the basket to increase Spain's lead to 62-57.
After Diaw missed a three-point attempt, Turiaf knocked Fernandez down in a heap at midcourt and was called for a flagrant foul. One of two free throws made it 63-57.
With 23 seconds left Batum ran into Juan-Carlos Navarro on an inbounds pass to him, knocking him to the floor and bringing more than half a dozen players together in what looked about to erupt into a fight before officials stepped in to separate them.
After some more free throws, the 2008 Beijing silver medallists left the court still on track for another Olympic medal.
Russia made the most out of their strength under the basket to beat Lithuania 83-74.
Andrei Kirilenko played his usual brilliant all-round game for Russia, while burly centre Timofey Mozgov operated down low with great effect to carry the Russians to the medals round in a gruelling battle marked by determined defence.
Kirilenko led Russia with 19 points and had a game-high 13 rebounds, while Mozgov added 17 points.
Russia will play either France or Spain in the semi-finals.
"It was a physical game. Lithuania, they're a physical team," said the 7-foot-1 (2.16 m) Mozgov.
"They were strong. The whole game was tough. We had to fight for rebounds, had to fight for position all game. Everybody's tired now but it was a good game."
Mozgov cleaned up around the basket in the first quarter to help lift Russia to a 17-10 first-quarter lead, and Kirilenko took over in the second quarter to allow the Russians to carry a 32-27 lead into the intermission.
Both teams struggled with their shooting in the first game played at the 20,000-seat North Greenwich Arena following preliminary round games played in the cosier 12,000-seat Olympic Basketball Arena.
Lithuania shot a poor 33 percent and Russia was not much better, connecting on 37 percent of their attempts, while making only 5-of-14 foul shots before halftime.
"We were playing great and then we go to the free throw line and we can't throw a ball in the ocean," lamented Russian coach David Blatt.
Both teams began to find the range in the second half.
Kirilenko took the initiative early and Mozgov weighed in later with a pair of dunks that helped Russia to a 52-39 lead toward the end of the third quarter.
Lithuania, however, battled back with an 11-2 run that made it 54-50 going into the fourth quarter.
A three-pointer by Rimantas Kaukenas made it a one-point game at 54-53 before the Russians recovered.
Mozgov and Kirilenko did not suffer the shooting woes of the rest. Kirilenko made 5-of-8 from the floor, and Mozgov was good on six of 11 shots.
The big centre said it was business as usual for Kirilenko, the former NBA Utah Jazz player who will be joining the league's Minnesota Timberwolves next season.
"He played very well," said Mozgov. "You know, I can't remember a game when he played bad."
Kaukenas scored 19 points to lead Lithuania, who made one last push to close within five points at 74-69 with two minutes left before Russia secured victory from the foul line.
"That was a boxing match, and I'm glad we were able to finish ahead on points, not by knockout, for sure," said Russia coach Blatt.