Photo

In her most vigorous assault yet on her Republican rivals, Hillary Clinton on Wednesday ridiculed the foreign policy prescriptions of Donald J. Trump and Senator Ted Cruz, calling them “reckless actions” that would alienate America’s closest allies, demonize Muslims and empower Russia.

“If Mr. Trump gets his way, it will be like Christmas in the Kremlin,” Mrs. Clinton said. “It will make America less safe and the world more dangerous.”

The speech, delivered at Stanford University, was written hurriedly after Tuesday’s terrorist attacks in Belgium refocused the presidential campaign from domestic issues like income inequality to the threat of global terrorism. With a firm lead in the race for delegates needed to capture the Democratic nomination, Mrs. Clinton seemed eager to turn to national security to launch her sharpest attacks yet on Mr. Trump and Mr. Cruz.

Yet in her own policy prescriptions — which included an “intelligence surge” to collect more data on the Islamic State, partnerships with Silicon Valley firms that have been suspicious of Washington, and beefing up security on soft targets like airport check-in areas — Mrs. Clinton resisted calls to distance herself from the Obama administration’s actions, and instead called for an acceleration of the approaches already underway.

That reflected how Mrs. Clinton is trying to appear muscular in the fight against terrorism while being cautious not to differentiate herself from her former boss, who remains widely popular among Democrats: Rather than arguing for major policy changes, she advocated moving faster and more dexterously.

“We face an adversary that is constantly adapting and operating across multiple theaters so our response must be just as nimble and far-reaching,” Mrs. Clinton said. “We need to rely on what actually works, not bluster that alienates our partners and doesn’t make us any safer.”

Mrs. Clinton’s remarks tilted heavily to pointed words for Mr. Trump and Mr. Cruz, rather than new policy solutions. “It would be a serious mistake to stumble into another costly ground war in the Middle East,” she said, though both men have hedged on whether they would argue for sending American troops. “If we’ve learned anything from Iraq and Afghanistan it’s that people and nations have to secure their own communities.”

Then she leapt on Mr. Cruz’s comment, several months ago, that he would “carpet- bomb” the Islamic State. “Proposing that doesn’t make you sound tough,” she said, “it makes you sound like you’re in over your head.”

That line got to the core of her argument: that as a former secretary of state, she has dealt with such crises before, and knows the importance of steadiness. Mr. Trump and Mr. Cruz have called that a weakness.

She portrayed Mr. Trump, whose mastery of Twitter has dominated the presidential campaign, as naïve about the Internet and the role it plays in ISIS’s recruitment. “When other candidates talk about building walls around America, I want to ask them how high does the wall have to be to keep the Internet out?” Mrs. Clinton said, referring Mr. Trump’s proposal to erect a wall on the Mexican border.

She particularly lambasted Mr. Trump over his proposal that the United States rethink its involvement in NATO, the Brussels-based organization that she called “one of the best investments America has ever made” and “the most successful alliance in history.”

In an interview with The Washington Post this week, Mr. Trump, who has tried to bolster his foreign policy credentials amid criticism from both parties that he is ill-suited to be commander in chief, said of NATO, “At what point do you say, ‘Hey, we have to take care of ourselves?’ “

“So, I know the outer world exists and I’ll be very cognizant of that,” Mr. Trump continued. “But at the same time, our country is disintegrating, large sections of it, especially the inner cities.”

Mrs. Clinton staunchly rejected the idea on Wednesday. “Turning our back on our alliances or turning our alliance into a protection racket would reverse decades of bipartisan American leadership and send a dangerous signal to friend and foe alike,” she said, arguing that President Vladimir V. Putin of Russia hoped to divide Europe.

In response, Mr. Trump wrote on Twitter: “Just watched Hillary deliver a prepackaged speech on terror. She’s been in office fighting terror for 20 years — and look where we are!”

Mrs. Clinton also reiterated her support for the thousands of Syrian refugees who have flooded into Europe fleeing violence, and rebuffed Mr. Cruz’s proposal to monitor American Muslim neighborhoods. She recited a line by New York’s police commissioner, William J. Bratton: “He said ‘Senator Cruz doesn’t know what the hell he’s talking about.’ “

Mrs. Clinton used the address to highlight her own foreign policy credentials, something that has not been central in the hard-fought nominating contest against Senator Bernie Sanders.

On Wednesday, she referred to a counterterrorism effort that allowed the United States to gain flight manifests as “an agreement the U.S. negotiated when I was secretary of state,” began a sentence with “having actually done this…” and joked after an introduction by Michael A. McFaul, a professor at Stanford and former United States ambassador to Russia, “What happens in Vladivostok stays in Vladivostok.”

In the audience were two leading members of the foreign policy establishment: William Perry, who was secretary of defense for Mrs. Clinton’s husband, and George P. Shultz, secretary of state under President Ronald Reagan. While Mr. Shultz is a lifelong conservative Republican, his presence was bound to be read — rightly or wrongly — as a signal about where he thinks his party has veered.

Mrs. Clinton’s speech, delivered in the heart of Silicon Valley to an audience that included the Apple co-founder’s widow, Laurene Powell, and technology executives and diplomats, took no hard position on one of the most contentious issues about combating terrorism: Whether to provide law enforcement and intelligence agencies an assured way into the contents of cellphones, or the data they transmit.

Rather than embrace proposed legislation that would require such access — and potentially create an opening in Apple and other products for hackers and foreign powers — Mrs. Clinton argued for the creation of a commission on encryption, an approach Senator Mark Warner of Virginia has proposed.

“There may be no quick of magic fix,” she said. “In the Apple case, the F.B.I. may have found a workaround, but there will be future cases with different facts and different challenges.” Mrs. Clinton was referring to the F.B.I.’s recent effort to postpone its court face-off with Apple, saying it may have found a way to get into the phone of one of the San Bernardino terrorists without the company’s help.

Mrs. Clinton, who spent much of the day in Silicon Valley fund-raising, imparted a vague declaration on the audience: “The tech community and the government have to stop seeing each other as adversaries,” she said.