The Brazilians, the defending Olympic champions, had lost two of their first three matches. A loss to China would have all but eliminated them from the quarterfinals.
Now 2-2 in the preliminary round, Brazil is still on the ropes with one match left against last-place Serbia on Sunday.
Losses to the top-ranked U.S. women and South Korea put the second-ranked Brazilians in the difficult spot in Pool B. The top four teams in each six-team pool advance.
The United States was undefeated and had already clinched a spot in the quarterfinals heading into Friday night's match against Serbia.
"It was a difficult match but we knew the difficulties," Brazilian libero Fabiana Oliveira said after 25-16 20-25, 25-18, 28-30, 15-10 victory over China. "We had a lot of pressure because we knew that if we lose, we could have been out of the Olympic Games."
The Chinese women, who are also 2-2 in the pool but have an advantage over the Brazilians because of sets won, were hampered without powerful spiker Wang Yimei, who has struggled with an ankle injury during the games and played just the opening set against Brazil.
Wang tore a ligament in her right ankle before the London Games, and appeared to re-injure it in a loss to the United States on Wednesday night.
Brazil wasn't helped when Turkey defeated South Korea 3-2 (25-16, 21-25, 25-18, 19-25, 15-12) in a later match on Friday. Neslihan Darnel had 27 points to lead Turkey, which improved to 2-2 and edged ahead of Brazil in the points standings for the fourth spot in the standings.
Turkey won despite missing middle blocker Eda Erden, who injured her ankle earlier in the competition.
Making its first-ever Olympic appearance in women's volleyball, Turkey faces a challenge with the United States in the final match.
Russia defeated Japan 3-1 (27-25, 25-17, 20-25, 25-19) to improve to 4-0 in Pool A. Japan falls to 2-2.
Ekaterina Gamova, Russia's 6-foot-8 spiker, had 29 points in the match. The Russians had already clinched their place in the next round.
The Dominican Republic won its first match of the Olympics with a sweep of Britain. Bethania de la Cruz de Pena had 12 points in the 25-9, 25-18, 25-19 win, which puts the Dominican Republic ahead of Britain.
Britain, playing in the Olympics as the hosts, surprised everyone by defeating Algeria earlier in the competition. Ranked 69th in the world, the British were not expected to win very many sets, let alone a match.