Jayaprakash Narayan, 76, a widely recognized moral force in India's politics who led a movement that ousted Prime Minister Indira Gandhi in 1977, died of a heart ailment yesterday at his home in Patna, India.

Mr. Narayan was one of the last major links to Mohandas K. Gandhi, the father of Indian independence, and a disciple of the nonviolence that Gandhi preached. A man of unquestioned integrity, he was able to exert an enormous influence in Indian politics by virtue of his pronouncements and the example he set.

Prime Minister Charan Singh, the head of the present caretaker government, declared seven days of national mourning for Mr. Narayan. He said his death had stilled "the conscience of the nation."

Mr. Narayan never held government office, although at one time he was considered the most likely successor to Jawaharlal Nehru, who became prime minister after India won its independence from Britain in 1947. Instead, he renounced the mainstream of politics to work among the poor.

In the early 1970s, he became increasinly outraged by the corruption in the government of Mrs. Gandhi and the Congress Party. He began to speak out against Mrs. Gandhi, whose father was Nehru. (She was not related to Mohandas Gandhi). In June 1975, he gave a speech in which he called on the police and the army to disobey what he described as illegal orders.

Citing this speech as one of the reasons for his action, Mrs. Gandhi declared a state of emergency. Using the repressive powers that it gave her, she ordered Mr. Narayan jailed. Thousands of others also were put behind bars. Mr. Narayan's detention lasted for 139 days.

After his release, he again began speaking out. In the elections of 1977, Mrs. Gandhi and the Congress Party were swept from power for the first time since independence. They were replaced by the Janata Party, which was made up of the groups that Mr. Narayan had welded together, Morarji Desai became prime minister.

During his imprisonment, Mr. Narayan kept a journal which was published later under the title "Prison Diary." In its first entry, he wrote:

"My world lies in a shambles all round me. I am afraid I shall not see it put together again in my lifetime . . . Where have my calculations gone wrong? . . . I went wrong in assuming that a Prime Minister in a democracy would use all the normal and abnormal laws to defeat a peaceful democratic movement, but would not destroy democracy itself and substitute for it a totalitarian system. I could not believe that even if the Prime Minister wanted to do it, her senior colleagues and her party, which has had such high democratic traditions, would permit it. But the unbelieveable has happened."

If the election of 1977 restored Mr. Narayan's faith in the viability of democracy in his country, subsequent events were a bitter disappointment to him. Although he suffered from kidney troubles -- he himself attributed them to his period of imprisonment -- and heart ailments, he frequently spoke out against the inability of the various factions of the Janata Party to work together.

On hearing of Mr. Narayan's death, Mrs. Gandhi, who was campaigning for forthcoming elections, issued a statement in which she said that, "differences apart," Mr. Narayan commanded universal respect and affection among Indians. She said the example of his life would be an inspiration to future generations.

The United News of India press agency reported that 50,000 persons gathered outside Mr. Narayan's house in Patna to pay their respects to him. Thousands followed a flower-bedecked vehicle carrying his body to the town hall, where it was to lie in state. Mr. Narayan was to be cremated Tuesday in traditional Hindu fashion. His funeral was expected to be the largest in India since that of Nehru, who died in 1964.

Mr. Narayan, who was known through India as "J.P.," was born on Oct. 11, 1902, in a village in the State of Bihar in northwest India. His father was a lower-ranking irrigation officer. It is said that the boy was 19 before he ever saw a city. In any case, he left high school a month before his graduation to join a student protest against British rule organized by Mohandas Gandhi.

In 1922, Mr. Narayan came to the United States as a student. He worked his way through Ohio State and earned a master's degree at the University of Wisconsin. On the way, he became a Marxist.

On his return to India in 1929, he rejoined Gandhi and Nehru in their nonviolent campaign against the British. Like them, he underwent several periods of imprisonment. In the 1940s, he abandoned Marxism -- he later became a critic of India's increasingly close ties with the Soviet Union -- and founded the Indian Socialist Party. Previously, he had been a member of the Congress Party of Nehru and Gandhi.

In 1952, he jointed Acharya Vinoba Bhave's campaign to improve the lot of Indian peasants by persuading large landowners to turn over part of their holdings to them. He spent most of the rest of his life on social reforms at the village level, believing that the key to solving India's problems lay in improving the lot of the small farmers and poor rural workers. His reemergence on the national scene in the early 1970s began as a student movement in the State of Bihar. It spread to other parts of the country, fueled in part by Mr. Narayan's reputation for absolute honesty in a country where political corruption is widely taken for granted.

As Mr. Narayan's movement grew, Mrs. Gandhi was facing increasing difficulties in her government and in the Congress Party. She saw Mr. Narayan as a person around whom this dissatisfaction could coalesce. The lines were drawn for the incidents that led to Mr. Narayan's imprisonment on June 26, 1975.

He had been in poor health for years before his detention. Upon his release his health was a factor in persuading the authorities to let him go he was hospitalized in India and then in the United States, where he was put on a dialysis machine because of kidney failure. In addition to his kidney and heart problems, he had diabetes.

On his release, Mr. Narayan commented, "After I feel better, I will continue to work for politics based on moral principles."

But as the 1977 election campaign progressed, his health worsened. He could play only an advisory role in securing the victory of the Janata Party at the polls and in the government that it later organized.

Mr. Narayan's wife, Prabhavati Devi Narayan, died in 1973. They had no children.