Marta was shown a straight red card in first-half stoppage time in Bordeaux for a rash and dangerous high tackle on Spain captain Olga Carmona right in front of the referee.
The 38-year-old was inconsolable as she walked off the pitch in what could turn out to be her final act at an Olympic Games.
The multiple winner of the FIFA women's world player of the year award is appearing at her sixth Olympics and featured in the teams that won silver in 2004 and 2008.
Her hopes of appearing again in this tournament first depend on whether Brazil make it through to the quarter-finals.
Athenea del Castillo tapped in midway through the second half to put already-qualified Spain ahead, and Alexia Putellas curled in a beauty for the second goal in the 17th minute of an interminable amount of injury time.
Spain's third straight win in Group C means they will head to Lyon for a last-eight tie on Friday.
Japan finished second in the group after beating Nigeria 3-1 at the same time in Nantes, with Maika Hamano, Mina Tanaka and Hikaru Kitagawa scoring their goals, the latter from a fine free-kick.
Christy Ucheibe replied for Nigeria, who go home without a point.
Japan, silver medallists in 2012, will play their quarter-final in Marseille.
Brazil, who finish with three points, can still go through to the last eight as one of the two best third-placed sides in the three groups, but that depends on the outcome of Wednesday's remaining matches.
Even if they do go through to the last eight, Marta would have to hope Brazil remain in the competition long enough for her to return after suspension.
The United States have already qualified from Group B before facing Australia, with Germany taking on Zambia at the same time.
Later on, Canada take on Colombia in Nice in Group A and the reigning Olympic champions have to win if they are to advance.
That is after an appeal against a six-point deduction related to a drone spying scandal was dismissed by the Court of Arbitration for Sport earlier on Wednesday.
Hosts France need a point against New Zealand to guarantee their own progress.