President Carter ordered the Secret Service yesterday to provide immediate protection for Sen. Edward M. Kennedy (D.Mass.), whose consideration of a presidential campaign has raised the fear of an assassination attempt such as those that struck down two of his brothers.

Secret Service agents began guarding Kennedy at about 6 p.m. yesterday, shortly after Carter issued the order, and will continue to do so for an indefinite time, according to government officials.

The president's action was apparently not prompted by a specific threat to Kennedy's life, but by a growing apprehension for the senator's safety that was conveyed to Secret Service and White House officials by Kennedy staff aides earlier this week.

In announcing Carter's directive, White House press secretary Jody Powell said:

"The president, based on Secret Service reports and on conversations with the Treasury Department [of which the Secret Service is a part ] by members of Sen. Kennedy's staff, directed the secretary of treasury to contact Sen. Kennedy and to take whatever steps are necessary to provide for the senator's protection."

Kennedy later issued a statement through his press secretary, Tom Southwick. "I have accepted President Carter's generous offer of Secret Service protection and I deeply appreciate his action in this in this matter," he said.

Southwick refused to elaborate on the statement.

Earlier in the day, Southwick said mail to Kennedy's office includes some threats on the senator's life, and that an average of one a week is considered serious enough to refer to authorities. But he said there has been no increase in the number of threats in the two weeks since Kennedy has made it clear that he may challenge Carter next year for the Democratic presidential nomination.

Nonetheless, Southwick said that because of Kennedy's "greater visibility," the senator's staff took certain security "precautions," including discussions with White House and Treasury Department officials on how best to protect the senator.

On Wednesday, Dr. Lawrence Horowitz, a Kennedy aide and specialist on national health insurance, met with Rear Adm. William M. Lukash, the president's physician. When the subject of Secret Service protection came up, according to Southwick, Lukash told Horowitz, "You should have it."

Treasury Department officials said Carter issued the protection order under his "inherent authority" in the Constitution. Twice before, Kennedy has been provided temporary Secret Service protection under similar presidential directives -- in 1968 after his brother Robert was shot to death in Los Angeles while campaigning for the Democratic presidential nomination, and in 1972 after an assassination attempt on Alabama Gov. George C. Wallace.

The specter of violence has haunted the Kennedy family since President Kennedy was assassinated in 1963. After Robert Kennedy was killed five years later, Congress enacted legislation to provide Secret Service protection to all major presidential candidates beginning with their primary campaigns.

It appeared unlikely last night that other announced or potential presidential candidates will be offered Secret Service protection immediately. According to a spokesman for the agency, the Secret Service has budgeted $16.9 million to protect presidential candidates next year.The protection is not scheduled to begin until after Jan. 1, although it could be moved up, as it was in the fall of 1975 after two attempts were made on the life of President Ford.

Carter ordered the protection for Kennedy not under the terms of the candidate law, but on his own authority after receiving an assessment of Kennedy's security situation from the Secret Service, according to Powell. The offer of protection was formally made to Kennedy yesterday afternoon by Treasury G. William Miller during a meeting in the senator's office.

Kennedy has promised to announce a decision on a presidential candidacy by the end of the year. In recent interviews, he has suggested that because of the risk to him he might not wage a fully traditional campaign that would place him constantly in public areas where security is most difficult to provide.