When he brought his first political campaign to the gates of the GE plant here 17 years ago, Edward M. Kennedy came away with one of the longest-lived jokes in American politics. But when he came back at the crack of dawn today, scrambling for votes like a rank beginner, the last son of Boston's "Royal Family" found little to laugh about.

Coughing and sneezing his way across icy Massachusetts, the tired, snappish Kennedy campaigned today, not to rack up an impressive victory (any margin is bound to be discounted as home-state advantage), but merely to stave off the ignominy of defeat, or near defeat in Tuesday's presidential primary.

Kennedy, who has won four Senate elections here by big margins, has suddenly found himself in the closest race of his Massachusetts career. Some polls show President Carter coming within 15 points of the native son and a few politicians have been thinking the unthinkable -- that the Georgian might actually win.

So Kennedy, who had originally scheduled a relatively easy day chasing votes and contributions in Florida, found himself instead on the campaign trail long before sunup, pleading with voters in Lynn and Roxbury and Worcester and Hyannis not to let an old neighbor down.

His first stop -- a traditional Kennedy campaign foray -- was the morning shift change at the General Electric engine plant here. The visit brought memories of Kennedy's first Senate campaign, and a vignette that has been retold at political gatherings around the country ever since.

In a televised debate in that 1976 campaign, the story goes, Kennedy's opponent looked at the camera and said, "This Kennedy has never worked a day in his life." The next morning as Kennedy was shaking hands at the plant gate here, a worker came up and said, "Kennedy, I heard what they said about you, how you never worked a day in your life. Well, I'll tell you something -- you haven't missed a thing."

The only echoes of that story at the plant gate today came from reporters who approached Kennedy every few minutes to repeat the punch line. The senator was not amused.

Kennedy also took time today to film what is literally an eleventh hour effort -- a TV commerical for broadcast statewide after the 11 o'clock news tonight.

The advertisement is a five-minute speech that opens with an appeal for Massachusetts loyalty ("Here I was raised and here I made my commitment to public service") and moves on to warn the Democrats that Jimmy Carter is a loser.

"As the foreign crisis fades," Kennedy says in the ad, "as the people look beyond it to our domestic crisis they will vote in the election to change policies that promise only prolonged hardship.And if the Democratic Party does not offer that change they will turn to the only alternative and return the White House to Republican rule.

"The country deserves better than a choice in 1980 between four more years of inaction and four new years of reaction."

Kennedy has been fighting a cold for a week now, and had hoped that a weekend in Florida would work a cure. But a cold rain fell Saturday while he rested at his mother's home in West Palm Beach, and he left Sunday in response to supporters here who urged him to hurry back to his home state and hustle votes.

Today he worked the community centers and Elks clubs and local newspapers like a neophyte competing for an open seat on the city council. He went through the day with an expression that seemed to say, "If I can just get through one more day of this" but a rally this evening at his home in Hyannisport seemed to buoy his spirits.