WASHINGTON - Senator Edward M. Kennedy, under treatment for brain cancer, made a brief, triumphant return to the Senate yesterday, stunning fellow lawmakers with a surprise appearance to vote on a critical Medicare bill that is central to the Massachusetts senator's healthcare agenda.

His Senate colleagues had not expected to see Kennedy, who is being treated with radiation and chemotherapy, for several more weeks or longer. Some feared that Kennedy, 76, would never be well enough to return to the chamber where he has served for nearly 46 years.

But with just minutes to go in a vote to protect Medicare payments to doctors, Kennedy, beaming and laughing, walked through the back doors of the Senate chamber and gave Democrats the vote they needed to stop a Republican filibuster and pass the bill.

The entire chamber erupted in cheers and applause as Kennedy - flanked by his son, his best friend, the Democrats' presidential nominee, and his fellow Massachusetts senator - strode into the well of the Senate floor. Lawmakers from both parties mobbed him; most shook Kennedy's hand and a few pecked him on the cheek.

Then, Kennedy gazed up at the Senate clerk to do what he has done many thousands of times since he arrived in Washington in 1963, but has been unable to do for more than a month: vote.

When the din had subsided, Kennedy raised his arms jubilantly and cast his first vote, signaling not only a victory for the legislation, but a temporary win over a deadly disease that has kept him from the job he loves since he was diagnosed May 20.

"Aye," he yelled, his arms high in the air.

Again, the packed chamber - filled with senators, staff, and spectators, including his wife, Victoria Reggie Kennedy, and his niece, Caroline Kennedy - exploded in celebration at the extraordinary moment.

"It was just a rush of emotion. We love the man," said Senator Richard J. Durbin, Democrat of Illinois and the majority whip. "The fact that he would make the sacrifice, and take the risk of coming here, means so much."

"It was so Ted Kennedy to decide to come, and to cast the deciding vote on an issue he cares so deeply about and that he identifies with," said Senator Susan M. Collins, Republican of Maine. "Everybody on both sides [of the aisle] had tears in their eyes," she said.

The bill would void a GOP effort to cut Medicare payments to doctors by 10.6 percent. It also would weaken subsidies to health maintenance, discouraging seniors from abandoning Medicare for private HMOs.

Kennedy, who left quickly after the vote, told reporters afterward that he flew down from Massachusetts yesterday afternoon because he did not want to miss such an important vote on Medicare, a program he has fought to protect for decades. Kennedy's face seemed slightly bloated but he appeared otherwise well, with his shock of white hair and broad smile intact.