It was to be Egypt's most intriguing political contest in years. Former foreign minister Ismail Fahmy, who quit in protest when President Anwar Sadat traveled to Israel in 1977, was challenging Mustafa Khalil, Sadat's current prime minister and right-hand man, for a seat in the Egyptian parliament.

But a funny thing happened to Fahmy on his way to the campaign trail. Election officals announced that there was no record of his having registreed to vote in the Cairo district where he and Khalil live, so he was disqualified.

The story was husbed up by the Egyptian press. But it was soon picked up by newspapers and radio stations in other Arab countries and spread quickly through Egypt. Egyptians say many people have concluded that the government pulled a fast one to prevent Fahmy from turning the election into a real test of sentiment about the peace treaty with Israel.

Many Egyptians, especially in the intellectual classes, are cynical about Sadat's claim to have established democracy in Egypt, and the Fahmy case has reinforced their belief that Sadat actually cannot tolerate dissent. The evidence, however, is not clear-out.

Fahmy admits he cannot produce a voter registration card. He has photographs of himself voting in recent referendums and plebiscites. But it may be that he was allowed to vote because in his years as foreign minister and deputy premier he was one of the most powerful men in Egypt and no one would challenge him.

Fahmy, a tough cigar-smoking diplomat who was the only Egyptian Sadat consulted about the decision to go to Jerusalem, now lives in comfortable isolation in an apartment overlooking the Nile.

He says he wanted to run in the June 7 parliamentary election because he is now "a free man, just an Egyptian citizen who wanted to make a contribution." As foreign minister he had no personal constituency, but since his resignation he has taken on stature as a man who quilt on a matter of principle and he still has friends in high places.

Egyptian Cabinet officers are not required to be members of the People's Assembly, or parliament. Fahmy was not a member when he was in the Cabinet, and Khalil is not required to stand for election to keep his post. But Sadat apparently has made a decision that his Cabinet officers should have the stamp of popular approval when possible and many are running, including Khalil.

Since the filing deadline has passed, Fahmy is out of the race. He was reluctant to discuss details of the dispute over his candidacy, but the story is now well known in Cairo.

He sought to run as an independent against Khalil, the candidate of Sadat's National Democratic Party. But his candidacy was barred over the voter registration issue. Since he had voted in other elections in his district, he filed a strong protest with the minister of interior. The minister spoke to him on the telephone and promised to help, but the issue was not resolved in time for Fahmy to qualify.

Fahmy has made no public accusations and there has been no official comment from Khalil or the minister of interior, Nabawy Ismail. But there was so much gossip about the case that the government finally replied in an oblique way last weekend.

The newspaper Akhbar el-Yom printed what it said was a letter from a voter inquiring about the story.

In its reply, the newspaper said Fahmy had asked the Interior Ministry to help him get a new voter registration card but "it turned out that the former minister is not officially registered in the election book and for him to be registered at this time would be illegal, because registration must be in December."

The interior minister, it said, invitged Fahmy to send aides in to scrutinize the voter rolls to search for his name.

As for Fahmy's participation in past elections, it said the rules are different in referendums and plebiscites and it is only necessary to produce an identification card. For a parliamentary election, it said, the rules are more tightly enforced. CAPTION: Picture 1, MUSTAFA KHALIL; Picture 2, ISMAIL FAHMY. Egyptians say many people have concluded the government pulled a fast one.