Ms. Carvalho first attempted to terminate the pregnancy by swallowing an entire pack of hypertension pills. When that didn’t work, she stuck a knitting needle in her uterus. By early May, when she was nearly four months pregnant, she sought the services of an underground abortion provider, who inserted a stalk of castor-oil plant into Ms. Carvalho’s uterus, according to the police report, which included an affidavit from the woman who administered the procedure.

Ms. Carvalho was instructed to remove the plant by pulling on a thread attached to it. But the thread came undone and the stalk remained inside her. As an infection took hold, she lay in a tiny bedroom in an aunt’s home. By the third night, when the aunt, Maria Aparecida Barbosa, went into the room to give her niece a blanket, the young woman’s lips were purple.

“I think I’m dying,” she told her aunt.

By the time Ms. Carvalho arrived at the hospital, the infection had entered her bloodstream.

Estimates of the number of abortions performed in Brazil each year range from 500,000 to 1.2 million. Each year, more than 250,000 women are hospitalized as a result of complications from abortions, according to the Brazilian Health Ministry. In 2016, the last year for which official figures were available, 203 women died as a result of botched abortions. Providing medical care for them has cost the government more than $130 million over the past decade.

Wealthy and middle-class women can have safer abortions by traveling abroad or resorting to medical professionals willing to perform them. Poor women, many of whom are black, make up a disproportionate number of those who die, become ill or get prosecuted as a result of the procedure, according to researchers, activists and public defenders.

Lívia Casseres, a public defender in Rio de Janeiro who is among those who will argue before the court, said that Brazil’s overwhelmingly male, and increasingly conservative, politicians had shown little interest in women’s reproductive rights.