The Carter and Kennedy campaigns squared off today for a showdown in the Feb. 26 New Hampshire primary battle, with both sides predicting a closer race in the wake of President Carter's narrow victory over Sen. Edward M. Kennedy Sunday in Maine's Democratic town caucuses.

While pre-Maine polls in both the Los Angeles Times and the Boston Globe gave Carter a 25-point lead over Kennedy in New Hampshire, leaders of the two camps agreed today that the contest was likely to be as close as the six points by which Carter edged Kennedy in Maine.

Carter strategists here and in Washington said they had abandoned any hope of achieving a quick knockout of Kennedy in his home base in New England and were digging in for what campaign chairman Robert S. Strauss called "the long drawn-out process" of accumulating enough delegates to win the national party nomination in New York next August.

Kennedy aides welcomed what one called "the war of attrition," believing that Carter's position will weaken as time erodes public preoccupation with the international crises in Iran and Afghanistan.

Carter returned to the White House from Camp David this afternoon and said he was grateful for "a second victory," a reference to his defeat of Kennedy last month in the Iowa caucuses.

Carter returned to the White House from Camp David this afternoon and said he was grateful for "a second victory," a reference to his defeat of Kennedy last month in the Iowa caucuses.

"We've had to make some sensitive decisions for our nation's security that were highly difficult politically," he said. "[These included] the grain embargo in the Mideast, our position on the Olympics, and more recently the decision on registration for the draft, and I'm pleased and grateful at the expression of support in the Midwest and New England."

The president refused to answer questions.

While White House press secretary Jody Powell told reporters in Augusta, Maine, that the president "would not even consider" a suggestion that he take up personal campaigning while the hostage situation in Tehran continues, campaigners on both sides were losing no time in mobilizing for the first primary.

Vice President Mondale arrives Tuesday for two days of surrogate activity for the President, to be followed on Thursday and Friday by First Lady Rosalynn Carter.

Kennedy, who revised his schedule today to expand his New Hampshire campaign time, comes into the state Wednesday for what will be a virtually unbroken 12-day effort leading up to the Feb. 26 voting.

California Gov. Edmund G. (Jerry) Brown Jr., who finished a surprisingly strong third in Maine, will be in New Hampshire Thursday night to try to repeat his successful formula here. Tom Quinn, Brown's campaign manager, said the governor intends to remain in New Hampshire "most of the time" until the primary.

Before the Maine caucuses, some of Brown's aides were hinting that he might drop out of the race this week without even waiting for New Hampshire because of his difficulty in raising money. Now Brown has vowed to stay in the contest.

Kennedy supporters here were cheered by what New Hampshire coordinator Dennis Kanin called "our first happy night in a long time," but they stopped short of predicting that the senator would beat Carter in New Hampshire.

Joanne Symons, Kennedy's state political director, said she thought Carter could be held to below 50 percent of the vote, as he was in Maine, and Massachusetts Lt. Gov. Thomas P. O'Neill III, Kennedy's New England coordinator, said the goal is "to do better in New Hampshire than we did in Maine," which would mean either a Kennedy victory or a very-near miss.

O'Neill said Kennedy had "stopped a fast-moving train" by shaving Carter's Maine victory margin far below the majority the president won in the Jan. 26 Iowa caucuses. "We cut Carter's margin 20 points in two weeks," O'Neill proclaimed, ignoring the fact that Kennedy had said the day after Iowa that he needed victories in both Maine and New Hampshire to remain a viable candidate.

But Ellis Woodward, spokesman for the Carter campaign in New England, conceded today that the close finish in Maine had "energized the Kennedy campaign," and the atmosphere at the Kennedy headquarters here was unmistakeably upbeat.

While awaiting the arrival of about 80 Kennedy organizers who had slogged their way from Iowa to Maine and are now heading for New Hampshire, Dudley Dudley, one of the originators of last summer's draft-Kennedy movement, said she had received word from Kennedy national headquarters that the financial picture has improved enough that "they are committed to spending everything they need to spend in New Hampshire, including a very significant media buy and direct mail program."

Woodward and other Carter aides conceded that in New Hampshire, as in Maine, Kennedy will be able to import far more volunteer canvassers -- mainly, college students -- than will Carter probably will have more professional organizers as well.

"We want to avoid giving him [Kennedy] any cheap victories," Jody Powell said, "but we're not going to shortchange our efforts down the road to match him man-for-man in New Hampshire."

Powell suggested that organizers may be less important in a primary election than in a caucus state. But the Kennedy campaign's Kanin noted that the Democratic vote is easier to target in New Hampshire because it is concentrated in cities on the southern edge of the state rather than being dispersed through small towns and rural areas as it is in Maine. Kanin said that suggests the effectivenes of footcanvassers, where Kennedy apparently will have the edge.

Similarly, both Symons and Dudley suggested that Kennedy's demand that Carter leave the White House and come out to campaign may be more persuasive in New Hampshire, where voters are accustomed to personal wooing by presidential candidates, than it was in Maine, where there is no tradition of such appearances.

But Kennedy strategists conceded that the possibility of another turn in the international wheel of fortune -- particularly the release of the hostages -- could override all these factors in a burst of national celebration for Carter's diplomacy.

Meantime, the Carter forces emphasized today their preparations for a long struggle with Kennedy. Powell told reporters in Augusta that the campaign now has headquarters and staff in 29 states, the District of Columbia and Puerto Rico, with 20 offices open in Illinois, where the March 18 primary could be a critical test between Carter and a revived Kennedy.

"We're going to run a campaign and try to win every place we can and be sure we get more delegates [at the national convention] in New York City than anyone else," Powell said.

But this week, unlike the days following Iowa, the Kennedy campaign is also planning ahead, with the announcement that Paul Tully, Kennedy's Iowa coordinator, is going to Illinois to aid the senator's lagging effort in that state.