Chancellor Angela Merkel went into isolation after learning that her doctor had tested positive.

BERLIN — Germany on Sunday barred groups of more than two people from gathering, except for families, and Chancellor Angela Merkel later said she herself was going into isolation because her doctor had tested positive for the coronavirus.

Ms. Merkel said she would isolate herself at home effective immediately after learning that a doctor who vaccinated her against pneumonia on Friday was infected, her office said in a statement. The chancellor will be tested regularly in coming days while carrying out her duties from home.

News that their leader was in quarantine quickly overtook headlines about the far-reaching social-distancing measures she had just announced.

The new rules, which will be in place for at least two weeks, are among the strictest imposed by any country on movement outside the home, and they came as global infections surpassed 300,000 and the death toll topped 13,000. In Germany, the number of confirmed cases had risen to more than 23,900 by Sunday, with more than 90 deaths.

“The coronavirus is spreading with worrying speed through our country,” Ms. Merkel said in a televised news conference on Sunday.

In the absence of a vaccine or a cure, she said, it is up to people to curtail their interactions, she said.

“Our own behavior,” she said, “is currently the most effective antidote we have: to reduce public life as much as is possible, to reduce contact with people through whom the virus could be transmitted.”

“In short,” she said, “that’s how we save lives.”

The chancellor, a trained scientist, has won wide praise for her calm and transparency during the crisis.

“We have to learn from experts — and from observing reality,” Ms. Merkel told Germans on Sunday.

Even with the chancellor in isolation, officials said, the government will continue operating as planned, with the cabinet preparing on Monday to make 150 billion euros — more than $160 billion — available to help the country weather the fallout.

Under the new restrictions, restaurants, which were previously allowed to seat customers during the day at a safe distance from each other, will be allowed to stay open but provide only delivery and takeout services.

Other businesses that had previously been allowed to stay open, among them hairdressers, massage studios and tattoo parlors, must now close their doors.

People will still be allowed to go to work, and to leave the home to care for relatives, shop and visit their doctors. Meetings deemed essential and exams can still take place, and people will be allowed out to go outside to exercise or get some fresh air — as long as everyone keeps a distance of 1.5 meters, or four feet, from one another.

Ms. Merkel’s announcement, made after a telephone conference with the governors of Germany’s 16 states, came after restrictions were put in place by the state of Bavaria, which on Friday severely limited movement outside the home.

In a major concession to the new reality, the German government also planned to take on debt for the first time since adopting a law requiring a balanced budget after the 2008 financial crisis. It is expected to approve an exception and borrow tens of billions of euros to help companies survive the looming recession and to secure millions of jobs.

The package is expected to be passed by Ms. Merkel’s government on Monday and voted on in Parliament later in the week.

Finance Minister Olaf Scholz justified the decision to borrow more than 10 times more than the country’s budget rules would normally allow, saying that “150 billion is a very big sum, but it gives us the opportunities that we need now.”

“We have a big challenge ahead of us,” he told the public broadcaster A.R.D. on Saturday.

Germany is just one of many countries limiting crowds to promote social distancing and stall the transmission of the coronavirus.

The United States government has said that no more than 10 people should gather in one place. Switzerland says people in groups of fewer than five must stay at least two meters (six and a half feet) apart, of face a fine. Austria’s chancellor, too, announced major restrictions on movement in public places, banning gatherings of more than five people.

The stringent restrictions imposed in Germany on Sunday were announced after the authorities said too many Germans were not following social distancing guidelines set last week.

The chancellor thanked the many Germans who have radically changed their lifestyles. And she warned those who have not yet done so that the rules are not optional.

“These are not recommendations by the state,” she said. “They are rules that have to be followed in our collective interest,”

Those who disobey them, she said, will be punished.

In a direct appeal to those who have taken a casual approach to social distancing, the chancellor said: “Please all join in. Do what is right for out country. Show reason and heart.”

“I am convinced this collective spirit, this ‘we stand for each other,’ will carry us through this difficult time,” Ms. Merkel said.

Some German cities have needed no prompting to clamp down.

In Freiburg, near Germany’s southwestern border with Alsace, France, the virus has been particularly aggressive in its spread, and local officials last week barred groups of people from gathering in public spaces.

Still, some other Germans have taken a far more cavalier, even defiant, approach.

There have been reports of “corona parties” held by youths in different corners of Germany, causing alarm among the authorities in a country better known for its citizens’ adherence to the rules. Some of the parties, where youths in large groups drank alcohol and chanted, “Corona, corona,” had to be broken up by the police.

On Wednesday, Ms. Merkel, in a somber address to the nation, asked Germans to avoid social contact in a spirit of solidarity with those most at risk in society. A day later, her chief of staff, Helge Braun, issued a sterner warning.

“We call on everyone to implement the measures so far passed,” Mr. Braun said. “And that means, apart from your core family, avoiding ideally all social contacts.”

“We will look at the behavior of the population this weekend,” he said. “Saturday is a decisive day.”

Ms. Merkel, meanwhile, demonstrated what responsible shopping looks like in the time of the coronavirus when she was spotted at her local supermarket in Berlin this weekend.

Keeping her distance from other shoppers, a smiling chancellor placed cherries, soap, several bottles of wine and toilet paper — one pack — into her shopping cart, photos on social media showed.

The chancellor paid by card, joining those Germans dispensing with a time-honored tradition: paying cash. Many stores have become averse to exchanging coins and notes during the outbreak.

Ms. Merkel acknowledged the toll the new rules of behavior are taking in a society used to freedom.

“Today we see everywhere in Germany that our cities, our traffic, our economic and private life look completely different from only a week ago,” she said. “I thank you for it. I know it means economic and human sacrifice when shops have to close, when you can’t just mingle with other people, or what is even more painful, see grandparents, meet friends.”