The new policy, which will go into effect in September, will provide six weeks of paid parental at full salary to all parents. Teachers who give birth will be able to use sick time, as well, for up to 12 weeks of paid leave for a vaginal delivery and 14 weeks of leave for a cesarean section.

Mr. de Blasio announced the agreement at City Hall, alongside teachers and elected officials. Some held babies or toddlers in their arms.

“The most important job for all of us who become parents is that of mom or dad,” Mr. de Blasio said. “That’s why paid parental leave makes so much sense. It’s always made sense but it makes even more sense in the 21st century when people are working so hard, such long hours, and struggling to make ends meet. It’s a fundamental matter of fairness.”

The deal comes after pressure from the United Federation of Teachers, a group that has been a political ally of Mr. de Blasio and has a membership that is 77 percent female. The policy applies to the union’s 120,000 members, which include social workers, guidance counselors and teachers. A petition by members demanding that the union negotiate for paid leave got tens of thousands of signatures last year.

The city said it would contribute $51 million a year to the union to help fund the new benefit, and estimated that 4,000 people a year would take the leave. To help cover the cost, the city will extend the union’s contract by two and a half months, which would delay raises for its employees.