BERLIN — The throng of people blocked the sidewalk outside a gray building on Sonnenallee, the main drag through the German capital's hip district of Neukolln.

A server from a kebab shop next door stuck his head out the window to see what the fuss was about.

“There’s no nightclub here,” one passerby quipped to the swelling line.

But those gathered in the winter chill were not seeking entry to one of Berlin’s famed techno parties. Rather, they hoped to be picked to rent a simple, two-room, 600-square-foot apartment advertised for $820 a month.

Scenes of crammed house viewings have become notorious in Berlin, where affordable apartments are a rare find. One apartment viewing in November drew headlines for attracting 1,800 potential renters.

In a potentially far-reaching move to address the problem, the parliament of the Berlin city-state on Thursday approved a five-year freeze on rents and a price cap of 9.80 euros per square meter — or about $1 per square foot.

Property values and rent prices in Berlin have exploded in recent years, making it one of the fastest-growing real estate markets in the world. While the average rent remains well below some other European capitals, surging costs have been a particular burden for residents of a city where salaries are relatively low, public housing stock is scarce and more than two-thirds of the population rents rather than owns.

“Housing is a need, like water,” said Stella Nikisch, 27, as she waited to tussle with more than 100 other prospective renters at another Neukolln apartment viewing. “The problem starts when you have people profiting from other people’s living situations.”

That philosophy has found a receptive ear within the left-leaning city government. And while the battle against gentrification is a familiar story in many major cities globally, the German capital is beginning to stand out for measures it is taking to fight the tide.

Under the new law approved Thursday, Berlin renters would be expected to save $2.75 billion over the five-year period, while landlords would lose the same, according to Berlin’s Urban Development Department.

That is, if the law stands: Chancellor Angela Merkel’s Christian Democratic Union (CDU) party plans to sue, arguing that the new law is unconstitutional, overriding federal government policy.

Rent control of the sort that restricts how much prices can increase each year is hardly new in cities such as New York and San Francisco. And it is being embraced in Europe. London Mayor Sadiq Khan, for instance, is campaigning for rent control to bring down housing costs.

But Berlin is going further than most with its rent ceiling — which is slated to go into effect in nine months and would apply to buildings constructed before 2014, to avoid discouraging new development. Landlords breaking the cap could face fines, while renters could apply to have their rent lowered if it surpasses prescribed limits.

“There is an attempt in lots of countries now to increase the amount of control on rent, but none as extreme as Berlin,” said Christine Whitehead, an emeritus professor in housing economics at the London School of Economics.

Historically, homeownership has been low in Germany, particularly in urban areas. Of course, in socialist East Berlin, property ownership was practically nonexistent until after the fall of the wall. But even after reunification, renting was considered a stable, practical option.

“One of the reasons it was working well was the population was declining and house prices were declining,” Whitehead said, adding that once there was pressure on the market, rent increases “came as a terrible shock to people.”

Berlin rental prices rose 30 percent over the past five years, according to Empirica, a real estate market data provider. That is double the rate of London’s rise over the same period. Over the past 10 years, Berlin rents rose more than 75 percent.

A portion of that increase can be attributed to population growth and higher demand, as migrants from the Middle East, European Union citizens from across the trade bloc and Germans from other parts of the country were drawn to the capital.

But there has also been a problem of supply. Housing scarcity has been compounded by sluggish construction, although the rate has sped up in recent years.

Many residents of Berlin — a mecca for artists and political and social activism — have balked as large U.S. property firms such as BlackRock and Berkshire Hathaway have entered the market, their real estate speculation further pushing up prices.

In a move now widely criticized as shortsighted, much of the city’s public housing was sold off in recent decades. And there’s a movement to buy some of it back, to preserve as public housing or otherwise stand in the way of significant rent hikes.

Last summer, the government stepped in to buy back 670 apartments in eastern Berlin that were slated to be sold to Deutsche Wohnen, the city’s largest private landlord, in which BlackRock owns a 10 percent stake. The tenants had protested the planned sale, fearing the new landlord would use loopholes to increase rents.

Left-wing politicians have gone so far as to suggest forcibly expropriating properties from the biggest landlords.

“The kind of interventions being talked about here are pretty radical measures,” said Michael LaFond, an affordable-housing activist. “In Berlin, the government is considering measures that people in [other] cities just wouldn’t get.”

The debate has been an emotive one, as demonstrated in a fiery parliamentary session before city representatives voted on the rent freeze and cap on Thursday.

As one might expect, the new law has faced vehement opposition from the real estate industry.

Reiner Braun, an economist with Empirica, suggested that the rent cap will deter new construction, perpetuating the supply shortage, and that most of the cap’s benefits will go to wealthy people in top-end apartments. The crush of people vying for affordable apartments will only get worse, Braun predicted.

“More people will be able to afford apartments,” he said, “but will they be able to get one?”

Opposition to the rent cap is not limited to the housing industry. Merkel’s Christian Democrats say it threatens Germany’s free market.

“It leads the housing market straight into a socialist planned economy,” said Jan-Marco Luczak, the Christian Democrats’ spokesman for legal policy.

The real estate industry and some economists say there is only one real solution to Berlin’s housing woes: building more. It’s an argument also made by backers of the bill, who say the rent regulations just give residents breathing space while that happens.

After the rent measure passed in the Berlin parliament Thursday, Katrin Schmidberger, a representative of the Green Party, praised it for sending a “strong signal to the real estate industry.” Because of the new law, property speculation in Berlin will soon be impossible, she said.

But she conceded that the city was entering “new legal territory.”

“I admit this law brings with it some uncertainties for the tenants and landlords,” she said. “It would be dishonest to pretend that we all enter a renters’ paradise now.”