Sen. Edward M. Kennedy scored a narrow victory in Tuesday's Pennsylvania primary, but failed to make headway in the important business of cutting into President Carter's lead in convention delegates.

With 99 percent of the state's precincts counted, Kennedy's margin stood at about 9,700 votes out of more than 1.4 million cast.

The missing precincts included about two dozen around Philadelphia, where Kennedy had scored heavily, and about eight in the western part of the state, where Carter was running stronger. A final vote may not be known for weeks.

Kennedy was expected to end up with 94 of Pennsylvania's delegates to the August Democratic National Convention, compared to the president's 91 delegates.

But that slender victory, as important as it was psychologically for the Kennedy campaign, was not enouugh to offset the president's lopsided win in Tuesday's Democratic caucuses in Missouri. As a result, Carter registered a net gain over Kennedy in number of delegates won during the day.

In Missouri, the president won 60 delegates, while Kennedy won 10 and 7 delegates in Tuesday's Vermont caucuses, a surprise after Carter's 3-to-1 victory in the nonbinding primary vote in March 4.

By late yesterday, United Press International credited Carter with a total of 1,115 delegates, Kennedy with 596.5 and said 32.5 were uncommitted. A total of 1,666 delegates is necessary to capture the nomination.

In the Republican primary, George Bush won an unexpectedly wide victory over Ronald Reagan in the nonbinding preferece poll, but Reagan apparently came away with about two-thirds of the delegates.

With 99 percent of the precincts counted, Bush had 617,000, or 53 percent, and Reagan had 525,380, or 46 percent. Rep. John B. Anderson received about 1 percent of the votes on a write-in campaign.

The separate voting for 77 district delegates -- all of whom were running as formally uncommitted candidates, with no official presidential preference -- harder to tabulate.

But it was clear that Reagan had the bulk of the support among those elected.

His Pennsylvania co-chairman, Tom Tripp, said the Reagan organization had endorsed at least 40 of those chosen Tuesday, and expected to win another eight of the 16 contests still being tabulated.

The Bush headquarters in Philadelphia said the picture was "too fuzzy" to be resolved.

The Philadelphia Inquirer's tabulation credited Reagan with 44 delegates, Bush with 22, and said 11 were uncommitted. UPI counted 26 for Reagan and 11 for Bush, with the rest uncertain.

Six at-large seats, previously allocated, divided two for Reagan, one for Bush and three uncommitted.

Reagan, relying on the estimate of his own headquarters, told supporters in Waco, Tex., that "we've got about 50 of the delegates and that's what counts." Reagan went into Pennsylvania with 547 delegates, compared to 96 for Bush, 56 for Anderson and 75 scattered and uncommitted.

Richard Wirthlin, Reagan's pollster and political strategist, said in Houston that Reagan would win the next four primaries -- in Texas on May 3, and Indiana, North Carolina and Tennessee on May 6 -- and "erase any doubt" about his eventual nomination.

But Bush encouraged by the come-from-behind victory in Pennsylvania, set his sights on later May contests in the District of Columbia, Maryland, Michigan and Oregon, and what his aides consider a showdown with Reagan on June 3 in Ohio.

Asserting that Carter already has the nomination "sewed up," the president's national campaign chairman, Robert S. Strauss, said the extremely close outcome in a state where Kennedy "had everything going for him" was a "devastating commentary on his ability to challenge the president."

"They failed to achieve their objective," Strauss said of the Kennedy campaign in Pennsylvania. "He made it Armageddon, we didn't. This was a major industrial state and he failed to pick up delegates."

Strauss did not formally concede Pennsylvania to Kennedy, but said he expected the Massachusetts senator to win by a few thousand votes.

The Democratic presidential contest now moves to Michigan, where caucuses Saturday will begin the process to select the state's 141 delegates.

The two campaign organizations have fundamentally different predictions of what is likely to happen between now and the convention in New York.

According to Strauss, Carter has suuch a huge lead in delegates that Kennedy in order to overtake him, would have to win more than 70 percent of the vote in the remaining primary and caucus states, which is virtually impossible.

By the beginning of June, he said, the president should be within about 50 delegates of the magic number of 1,666. On June 3, the last primary day, when almost 700 delegates will be selected, Carter should build a comfortable pad into his delegate margin at the convention, Strauss said.

According to Kennedy aides, the Carter camp is counting on the support of a large number of delegates from caucus states who are not finally chosen or legally bound and who could turn in the end to Kennedy. The senator yesterday pointed to the results of the Vermont caucuses -- which he finally won despite the president's 3-to-1 victory in a nonbinding "beauty contest" vote n the state in March -- as evidence of erosion in Carter's strength.

According to Paul Kirk, Kennedy's chief political strategist, Kennedy should begin closing the delegate gap on Carter in the remaining primaries, with neither candidate having enough for the nomination after the June 3 results. The fight would then come down to the 367 delegates to be chosen in state conventions after the last of the primariess, Kirk argued.

While Kennedy in fact lost ground in the overall results from Tuesday's contests, his apparent narrow win in Pennsylvania allowed him to continue arguing that he can close in on Carter's lead by winning other large, industrial states such as Michigan, New Jersey, Ohio and California.

For the president, the Pennsylvania results meant that he is almost certain to have Kennedy as an opponent all the way to the convention, with all the risks of growing bitterness and a weakened candidacy in the fall that that implies.

As votes trickled in from Carter strongholds in rural areas early yesterday morning, Kennedy's lead -- once 10 points -- all but vanished and a wave of optimism swept the Carter campaing. At 1:30 a.m. yesterday, the president's pollster, Patrick Caddell, said his analysis of uncounted votes showed Carter winning narrowly.

It turned out, however, that there had been an earlier error by the News Election Service, which tabulates election returns, that inflated the president's apparent margin in the Pittsburgh area. At 4 a.m. yesterday, having learned of this error, Caddell sat on the floor of his hotel suite poring over the numbers and finally concluded that Carter had lost.