Senator Bernie Sanders campaigning in Los Angeles on Saturday. Hillary Clinton has made clear that she plans to declare the Democratic race effectively over after the California primary on Tuesday.CreditCreditMonica Almeida/The New York Times

WEST HOLLYWOOD, Calif. — Senator Bernie Sanders defiantly vowed again on Sunday to take his campaign to the Democratic National Convention this summer, even as Hillary Clinton edged closer to clinching the party’s presidential nomination and the final primary contests drew near.

Two days before Tuesday’s primaries in California and five other states, Mr. Sanders repeated his pledge not to concede even if Mrs. Clinton acquires enough delegates to reach 2,383, the threshold for securing the nomination.

A win in California is critical to Mr. Sanders’s plan to stay in the race through the convention and would give him a significant lift.

But with her victory in the Puerto Rico primary on Sunday, Mrs. Clinton is only 28 delegates short of the threshold and will most likely declare victory on Tuesday.

Mr. Sanders, however, insists that the convention will be contested because he is still lobbying superdelegates — party officials and state leaders who cast their final votes at the convention — to withdraw support from Mrs. Clinton and back him instead. He plans to make the case that he is a stronger candidate against Donald J. Trump, the presumptive Republican nominee. A number of polls, he said, show he can beat Mr. Trump by larger margins than Mrs. Clinton can.

On Sunday, Mr. Sanders opened a new line of attack against Mrs. Clinton, criticizing donations made by foreign governments while she was secretary of state to the Clinton Foundation, the organization founded by former President Bill Clinton.

When Mr. Sanders, who greeted fans in West Hollywood, was asked by reporters if he remained committed to pushing for a contested convention, he said he “absolutely” was.

A convention is typically seen as contested when a candidate cannot reach the necessary delegate count using both pledged delegates and superdelegates. In 2008, Mrs. Clinton conceded to Barack Obama shortly after the final primary and before the convention. But Mr. Sanders is promising to break with tradition and extend his fight further than initially expected.

Mr. Sanders reiterated his stance on Sunday at a restaurant filled with disco lights as he urged supporters to back him.

“We need a real change in this country,” Mr. Sanders said to a cheering crowd at the restaurant, Hamburger Mary’s, in West Hollywood, “and we need a government which represents all of us, not just the 1 percent.”

During a news conference on Saturday in Los Angeles, Mr. Sanders said it would be wrong for Mrs. Clinton to claim victory on Tuesday based on her total delegate count. News media outlets should not call the race, he said, unless she reaches the threshold with only pledged delegates.

“It is extremely unlikely that Secretary Clinton will have the requisite number of pledged delegates to claim victory on Tuesday night,” Mr. Sanders said. “Now, I have heard reports that Secretary Clinton has said it’s all going to be over on Tuesday night. I have reports that the media, after the New Jersey results come in, are going to declare that it is all over. That simply is not accurate.”

Mrs. Clinton leads Mr. Sanders in both pledged and total delegates.

In a sign of his campaign’s urgency to win in California, Mr. Sanders criticized the Clinton Foundation during an interview on Sunday on CNN’s “State of the Union.”

“If you ask me about the Clinton Foundation, do I have a problem when a sitting secretary of state and a foundation run by her husband collects many millions of dollars from foreign governments, governments which are dictatorships?” Mr. Sanders said.

“You don’t have a lot of civil liberties or democratic rights in Saudi Arabia,” he told the interviewer, Jake Tapper. “You don’t have a lot of respect there for opposition points of view for gay rights, for women’s rights. Yes, do I have a problem with that? Yes, I do.”

Mr. Sanders and Mrs. Clinton spent Sunday campaigning in California, where polls indicated a tight race. Mrs. Clinton and Mr. Clinton visited black churches, appealing to a demographic that had given her important support in past nominating contests.

In Oakland, Mrs. Clinton spoke at Greater St. Paul Church. Tailoring her remarks to her audience, she recalled working briefly in Oakland in the 1970s, and she praised the Golden State Warriors, who were set to host Game 2 of the N.B.A. finals.

Mrs. Clinton also talked about issues like gentrification and gun violence and told congregants how difficult it was to be president.

“I wish it was only about making speeches,” Mrs. Clinton said. “You know, just get up there and promise the moon and make all of these rhetorical flourishes. That’d be a lot easier than what the job is.”

Mr. Clinton visited First African Methodist Episcopal Church in South Los Angeles, where he took aim at Mr. Trump and addressed criticism that he and his wife were part of the “political establishment.”

“This is not an establishment campaign,” he said. “This is an inclusion campaign.”

Mr. Sanders spent much of his day walking around greeting voters in several places, including the Santa Monica Pier, where dozens of fans hugged and snapped photos with him. Some shouted, “That’s our next president!”

But there were signs of opposition from Clinton supporters. One woman shouted, “Get out of the race!” As Mr. Sanders shook hands, he quickly moved past Jenny Swiatowy, 33, who sat next to a fruit arrangement with a sticker showing her support for Mrs. Clinton.

“In the beginning, I thought it was great for him to come out as a new candidate with a new voice and to start bringing out the young new voters,” said Ms. Swiatowy, who works at a record label. “But it’s time to concede and unite the party.”

Mr. Sanders, though, was not bowing to the pressure.

“See you in Philly,” he told one smiling supporter.

Maggie Haberman contributed reporting from New York, and Thomas Kaplan from Oakland, Calif.

A version of this article appears in print on , Section A, Page 13 of the New York edition with the headline: Clinton Wins a Primary While Sanders Promises a Fight to the Convention. Order Reprints | Today’s Paper | Subscribe