Sen. Edward M. Kennedy upset President Carter in Arizona's Democratic precinct caucuses this weekend, although his gains were offset by Carter in South Carolina as the two battled for national convention delegates in five states.

"The Southwest now has spoken," an ebullient Kennedy rejoiced yesterday at a campaign stop in Philadelphia. While the senator's 55 percent-to-45 percent Arizona victory was expected to net him only three more delegates than Carter there, it brought him a big psychological lift as the April 22 Pennsylvania primary draws near.

"when the economy is wrong, everything is wrong and I believe that the American people are going to nominate in the Democratic Party a nominee who's got a program to deal effectively" with economic problems, Kennedy told an early-morning news conference.

"the Southwest now has spoken. The Northeast has spoken," he said, referring to last months' victories in New York and Connecticut. "the next state is Pennsylvania and we look forward to carrying the same message . . . and we're hopeful of getting a similar response."

With 65 of 70 Arizona precinct caucuses reporting, Kennedy led with 9,738 votes to 7,592 for Carter and the senator's margin was growing.

Kennedy seemed assured of eventually claiming 16 of the state's 29 delegates to the Democratic National Convention, with Carter getting the other 13.

The senator also was doing well in Alaska, where the Democratic Party held district conventions over the weekend.

With results from five of the 22 conventions reported, Kennedy supporters claimed 34 of the 289 delegates being selected for the state convention in Fairbanks on May 17-18. Carter's backers picked up 12 convention seats, while 32 went to uncommitted delegates.

At Fairbanks, Alaska Democrats will name 18 national convention delegates to cast the state's 11 votes. The state has traditionally sent an uncommitted delegation to the convention, but an active Kennedy organization is working to end that tradition in 1980.

White House press secretary Jody Powell said that in Arizona, "the Kennedy people did a good job."

"they had us looking the other way," Carter's spokesman said. Powell added that farm union leader Cesar Chavez "did a great job (for Kennedy) in the Hispanic communities."

The kennedy camp's attention to Mexican-American and other ethnic communities apparently paid off Saturday. In Maricopa County, which includes Phoenix, the senator captured 14 of 18 districts and did extremely well in Mexican-American communities in Phoenix and in Pima County (Tuscon), Rick DeGraw, Kennedy's Arizona campaign coordinator, told Washington Post special correspondent Don Harris. The senator also ran well in Phoenix's Jewish community and in outlying counties where many Apache and Navaho Indians live.

Although such well-known Kennedy family members as sisters Eunice Shriver and Pat Lawford and nephew Robert Kennedy Jr. stumped the state, DeGraw said organization was the key to the senator's upset victory.

The main surprise was Kennedy's strength in conservative areas -- even carrying Sen. Barry Goldwater's (R) home district of Paradise Valley.

"jimmy Carter found there's a little cactus growing in the Rose Garden," a grinning Kennedy told a cheering labor audience in Philadelphia yesterday.

It wasn't a lost weekend for Carter, by any means. The president, who held a more than 2-to-1 national delegate lead over Kennedy going into the caucuses, picked up another half-dozen delegates in South Carolina and maintained his hold on Virginia.

Early returns from party conventions in the four largest counties in the state of Washington indicated Carter was hanging on to the lead he mustered in that western state in precinct caucuses held last month.

With 1,666 votes needed for nomination, the president had garnered 891 delegates before Saturday's round of caucuses. Kennedy had won 439 delegates.

In South Carolina, Carter's forces took 34 of the state's 37 Democratic National Convention delegates as the state party concluded its selection process. Kennedy won only one delegate and the other two went uncommitted. The president figured to do well since he had set a winning pattern in the earlier precinct caucuses. Going into Saturday's convention, Carter had been poised to claim at least 28 of the state's 37 delegates.

In Washington state, Democrats held conventions in the state's four largest counties. State party chairman Joe Murphy has said the president should beat Kennedy by 2 to 1. Carter had established such a margin in the state's March 11 precinct caucuses.

With incomplete, unofficial returns, the president seemed assured of winning at least 29 of the state's 57 national convention delegates, with Kennedy in line for as many as 14 and another 14 going uncommitted.

Conventions were held Saturday in five of Virginia's 10 congressional districts to choose 23 of the 64 national delegates. With all five districts reporting returns, Carter had won 21 and Kennedy 2.

Twenty-one more delegates will be chosen in the other five districts at meetings scheduled on April 19 and May 3. Fourteen delegates will be elected at the May 16-17 state convention in Richmond and the other six will go to top-ranking state party officials. Carter is expected to end up with 59 or 60 of the state's 64 delegates to the nominating convention.