Four years of quiet negotiations about building mosques, opening Muslim cemeteries and teaching Islam in public schools are nearing an end just when Germany is embroiled in a noisy debate about Islam and the integration of Muslim immigrants.

The deal seems set to go through, but the national debate on Islam and local political changes could make its approval more difficult than expected, politicians and Muslim leaders said.

“It’s important for us that this agreement makes clear that we are part of this society,” said Zekeriya Altug, chairman of the Hamburg branch of DITIB, a Turkish-German mosque network that is one of Germany’s largest Muslim organizations.

“We’re close to wrapping this up,” said Norbert Mueller, a German convert who is a board member of Schura, the largest mosque association in this north Germany port city.

Germany has about 4 million Muslims, mostly of Turkish origin, in its 82 million population. Long treated as migrant workers due eventually to return to their countries of origin, they are now an established minority that wants equal rights.

The agreement in Germany’s second-largest metropolis, a city-state in the country’s federal system, would set out their rights and also their duties, such as consulting neighborhood residents before building mosques or erecting minarets.

Altug said many rights were already allowed under various German laws, or granted as local exceptions. “This agreement should bring all this together in a single text,” he said.

Equal status with Christians and Jews could be more controversial when the agreement comes up for discussion in the local assembly for Hamburg, a traditionally Lutheran city where Muslims make up about 5 percent of the 1.7 million population.

President Christian Wulff set off a heated debate by saying in his Oct. 3 German Unity Day address that the country had Christian and Jewish roots but the presence of a large Muslim minority meant that Islam too now “belongs to Germany.”

Conservative leaders argued Germany had a “Judeo-Christian heritage” that Islam did not share and demanded Muslims do more to integrate into German society.

The Hamburg agreement would integrate Muslims in several practical ways. For example, city schools would have to hire Muslims to teach Islam in religion classes all pupils attend. These are now run by teachers from the local Lutheran church.

It would ensure burial rights in municipal cemeteries, so Muslims can be interred in shrouds rather than coffins and have no other religious symbols nearby. Many immigrants prefer to be buried in their original countries to ensure a Muslim burial.

Muslim pupils would be free to skip school on 2 or 3 Islamic holidays and Muslim preachers could be posted in prisons.

Two other states, Lower Saxony and North Rhine-Westphalia, are also considering recognizing Islam. Since recognition of religions is a state issue under German law, some other states may not follow Hamburg’s example.