Twenty months after the voters threw Indira Gandhi and her party from power, the woman who led India for more than a decade as its prime minister appeared on her way back to parliament yesterday in a special by-election.

Her victory, according to political analysts, would represent a significant setback for Prime Minister Morarji Desai and his ruling Janata Party. Once back in Parliament, Gandhi is expected to take over a leader of the opposition, a role that will give her a respected and powerful forum for her strident attacks on a ruling party that already is weakened by internal divisions at the top.

In addition, her election would likely be cast as a reprieve from the voters on the excesses of her nearly two years of rule under emergency powers that led directly to her downfall in March 1977.

Since Gandhi now faces charges of abuses of power during that period, observers felt her victory could lead to great pressure to block further prosecution. There were allegations during the campaign that this was one of the major motivations behind her decision to attempt to return to national politics.

For her try, the disgraced former prime minister turned to one of the two states still under control of her party - Karnataka, in southern India more than 1,000 miles from the regions in northern India, where her former district lies, but where the excesses of emergency rule fell most heavily. Gandhi had no prior close connection with Karnataka and does not speak the local dialect.

While counting was not yet completed late last night, Gandhi held a 43,850-vote lead over her main opponent, Veerendra Patil of the Janata Party, with about 230,000 votes counted. More than 453,000 persons voted in the Sunday election, 76 percent of those eligible and a high turnout reflecting the intense and often violent nature of the campaign.

Gandhi, who was at her New Delhi home while the votes were being counted, told photographers even before the decisive trend in her favor developed that she was going to bed.

"I am not so excited about defeat or victory," she said. "I am always in a steady mood."

In the elections last March in which Gandhi and her party were heavily defeated, particularly in northern India, the Chickmagalur constituency in Karnataka returned a Gandhi supporter by more than 64,000 votes. When Chandre Gowda stepped aside, creating an opening for Gandhi to run, it was considered a "safe" seat for her.

The Janata Party threw all its resources into the race, however, a reflection of how much it had at stake. Industry Minister George Fernandes, a native of the state, ran Patil's campaign, and top Cabinet minister from New Delhi stleamed into the state.

Gandhi, by all accounts, campaigned indefatigably, getting up at dawn and moving from village to village briefly addressing adoring crowds in the predominantly agricultural constituency. Though she could not speak the language of most of the people, since she is from northern India where the local language is different, the villagers did not seem to mind hearing from her through interpreters, getting caught up in the glitter of the big names and the whirl of campaign caravans.

Time and again, she attacked the Janata Party for its policies allegedly discriminating against Moslems, untouchables, lower-caste Hindus, or any of India's myriad minorities. She warned the villagers not to listen to the "propaganda campaign" being waged against her.

Where Gandhi avoided the bitter memories of the period of emergency rule, it was at the core of the opposition campaign. Patil was chief minister of Karnataka during the emergency period and fought the directives being sent down from New Delhi. Later defeated in state elections by a Gandhi loyalist, his efforts to soften the impact of emergency rule may have worked against him by leaving Gandhi with a less severe image.

Northern India bore the brunt of the more than 100,000 arrests and thousands of forced sterilizations, and it is there the memories are most bitter.

Patil attacked again and again on Gandhi's actions during the emergency. "Both of us symbolize two entirely different political thoughts," he said during the campaign. "She is a fascist and I am a democrat. The old equations of caste and community cannot operate in this election."

Fernandes recalled the case of his brother Lawrence, who was jailed and severely beaten during the emergency by police trying to find out where George Fernandes was hiding underground. Lawrence did not know, but his health has deteriorated sharply before the police believed him.

Independent observers concede, however, that the Fernades case is a rare one, for Karnataka, and that there were actually some gains for the poor in the state during the emergency. It is to this constituency that Gandhi directed her appeal, and it apparently was successful.

To them, Gandhi is remembered more as the daughter of the late Prime Minister Jawharlal Nehru and as a symbol of national power and of the Congress Party that ruled India from independence until Gandhi's defeat in 1977, only a fraction of which she now actually represents.

Gandhi's Indira Congress, with some 70 seats in the Lower House, is the largest of the opposition parties, which present no direct threat to the control of the Janata Party. It holds the allegiance of at least 270 of the 525 members.

Nevertheless, the parliamentary forum will give Gandhi a degree of respect she could not command as she launcher attacks on Desai from the lawn of her bungalow in New Dehli. Desai has been unable to overcome divisions within his party's leadership and has been plagued by continuing outbursts of religious and caste violence - all of which will give Gandhi plenty of targets to attack in the months ahead.