Two years ago, Ben Kingsley, an actor with the Royal Shakespeare Company, was playing Mr. Squeers in the original London production of ''Nicholas Nickleby.''

''It was killingly hard work and burned up a lot of an actor's brain cells,'' Mr. Kingsley recalled. ''So my wife started putting books in front of me in order to relax me and ease my blasted mind. One of the books was a biography of Gandhi.''

Six days later, deeply immersed in the life of the Indian leader Mohandas K. Gandhi, Mr. Kingsley received a call from Sir Richard Attenborough, the actor and director, who had been trying for almost 20 years to start a movie about Gandhi. For nearly that long, Mr. Attenborough had also been searching for the right actor to play Gandhi, with little success. Would Mr. Kingsley be interested and available for a screen test?

He was indeed. ''And from the moment Ben came on the screen, he was absolutely mesmeric,'' reported Mr. Attenborough, who produced and directed the film. ''There was no question he was the one.''

Although Mr. Kingsley has been acclaimed in Britain for roles ranging from Hamlet to the title part in Brecht's ''Baal,'' the 38-year-old actor is little known in the United States. That should change with ''Gandhi,'' which opened last week at the Ziegfeld Theater in New York. An immense 3-hour 20-minute epic biography, the film traces the life of Gandhi from his arrival in South Africa as a young lawyer in 1893, through his crucial role in the birth of modern India, to his assassination in 1948 at the age of 79. The cast also includes Sir John Gielgud, Candice Bergen, Martin Sheen, Athol Fugard, Trevor Howard, John Mills and the Indian stage actress Rohini Hattangadhi as Gandhi's wife, among scores of others.

Provides the Magnetic Center

But it is Mr. Kingsley who provides the magnetic center. Mr. Attenborough's search for the perfect Gandhi was long and frustrating, but when he finally found Mr. Kingsley, his choice seemed eerily appropriate. Although born and raised in England, Mr. Kingsley is half Indian: his mother was an English model and his father, a physician, was Indian. Mr. Kingsley's family has not lived in India for three generations: his paternal grandfather, a spice trader, left India to settle in Zanzibar, where Mr. Kingsley's father lived until going to England at the age of 14.

Despite what Mr. Kingsley calls ''a thoroughly English upbringing'' in Manchester, he was born Krishna Bhanji (he changed his name as a young man beginning his theatrical career) and bears a striking physical resemblance to Gandhi. When he began to research the life of Gandhi, Mr. Kingsley learned that his own family had even come from the same village as the Indian leader.

''There are certain historical figures and moments that I have personally always found overwhelming,'' said Mr. Kingsley. ''Martin Luther King Jr.'s famous speech, for example, and old newsreel films of Gandhi. That kind of documentary evidence feeds me as an actor, and I have always collected them. Gandhi was one of my source figures: a prototype human being. He was an utterly remarkable man, in his intellect, his energy and his integrity - a combination that was constantly apparent.''

'An Awesome Responsibility'

But the prospect of actually recreating Gandhi on film was daunting. ''My reaction was similar to my reaction when I got the part of Hamlet,'' said Mr. Kingsley. ''It's an awesome responsibility, and the weight of it sort of lands between your shoulder blades and bends you.''

He prepared for the role ''methodically and scientifically,'' he said, reading biographies, screening newsreel footage and poring over ''every photograph I could get my hands on.'' He continued: ''All you can do is just look at them and hope something goes in'' - Mr. Kingsley tapped his head -''that when the time comes will govern how you place yourself and use your body. Of course, the more you learn the more you realize how impossible the task seems.''

In his quest for authenticity, Mr. Kingsley not only shaved his head and lost 20 pounds on Gandhi's vegetarian diet, but he also studied yoga, began to meditate and learned to spin cotton thread on a wooden wheel, as Gandhi had done while holding conversations.

For Mr. Kingsley, such training is the catalyst for an alchemy even he does not understand. ''When I have totally immersed myself in the mechanical, logical preparation of a part, if I and my craft are totally bonded and fully exploited, something else in me is awakened and begins to inform my work,'' he explained. ''The preparation is entirely systematic, practical and scientific, but when I play the role, whether it is Hamlet or Gandhi, some other kind of information comes to the forefront, a certain energy is released. There is some essence in me that adheres itself to the work. I can't tell you what it is - I can't tell you what the heart of my mystery is - because I don't know; all I know is that it is the product of extremely hard work.'' Thought He'd Be a Doctor

Mr. Kingsley discovered his gifts as an actor rather late; he grew up expecting to become a doctor, like his father. But by the time he graduated from high school, he said, ''I had realized medicine was not right for me, and had to radically rethink what to do with my energies.'' Aimless, he joined an amateur dramatic society, found that he was ''transported'' by the thrill of audience response and went on to a job with a children's theater company in London. His progress was swift: after brief stints with two other repertory companies, Mr. Kingsley joined the Royal Shakespeare Company in 1967.

He spent several seasons working there full-time, culminating in the role of Demetrius in Peter Brook's production of ''A Midsummer Night's Dream.'' Mr. Kingsley then left the company to do a wide range of other work, including several plays by Athol Fugard, the South African writer, who appears as General Smuts in ''Gandhi.'' Mr. Kingsley appeared in ''Hello and Goodbye,'' ''Statements After an Arrest Under the Immorality Act'' and, with Paul Scofield, in ''Dimetos.''

He has also appeared at the National Theater as Mosca in ''Volpone,'' Sparkish in ''The Country Wife'' and Trofimov in ''The Cherry Orchard.'' Mr. Kingsley is now an associate artist of the Royal Shakespeare Company. ''That means I have an emotional and artistic link but can do other things,'' he said. And he returns to the fold from time to time for various projects.

'Hamlet' a 'Turning Point'

Playing Hamlet with the company in 1975 was ''probably the most important move I've ever made in my life,'' he said. ''That was a turning point in my approach to my work and my career.''

And it was in ''Hamlet'' that Richard Attenborough first saw Mr. Kingsley, whose work had been called to his attention by Mr. Attenborough's son, Michael, who is also a director. Of his six months in India filming ''Gandhi,'' Mr. Kingsley says, ''I've never been happier in my life, in terms of exercising my craft on something I utterly believed in.''

Mr. Attenborough and Mr. Kingsley both hope that the film will, among other things, revive and clarify Gandhi's image. ''Either he's become deified and mystified - which is very sad, because he has a lot to say to us in terms of political ideas - or people don't seem to know about him at all,'' the actor remarked.

After finishing the film, Mr. Kingsley went home to be directed by his wife, Alison Sutcliffe, in a one-man play about Edmund Kean at the Harrogate Studio Theater in Yorkshire. When the Kingsleys had their first child last summer, they ''named him Edmund, after Edmund Kean,'' Mr. Kingsley added.

In Harold Pinter Film

His most recent project was the film version of ''Betrayal,'' Harold Pinter's play about infidelity, in which Mr. Kingsley co-stars as the husband with Patricia Hodge as his wife and Jeremy Irons as his best friend.

Mr. Kingsley recognizes that such exposure may have a marked impact on his career. ''I'll be a lot better known after 'Gandhi,' I suppose,'' he mused. ''It's possible that work will now be offered to me outside of the National Theater, the R.S.C. and a few English directors, as in the past. I do want to do more films and work with certain directors I've always admired.''

Whatever his arena, however, Mr. Kingsley seems at peace with his choice of life's work. ''I think I've recognized my function,'' he said softly. ''Until one recognizes one's function, one is denied an essential ingredient in life. A lot of people are not given an opportunity to recognize their functions; their choices can be too limited. But I'm a storyteller. I recognize the need to tell people stories, to engage them on a particular level. I therefore need and thrive on the level of compressed association with my fellow human beings that only the theatrical event can bring. With essential truth in mind, it doesn't really matter what the story is.''