The largest union representing federal workers took the Trump administration to court Thursday to block a new executive order that severely restricts the time employees may spend on union activity, claiming the president’s action violates the First Amendment and oversteps his constitutional authority.

The lawsuit filed in U.S. District Court for the District by the American Federation of Government Employees ratchets up ­labor-management tensions that have simmered at federal agencies since President Trump took office.

“This president seems to think he is above the law, and we are not going to stand by while he tries to shred workers’ rights,” J. David Cox Sr., national president of the AFGE, said in a statement announcing the lawsuit.

“This is a democracy, not a dictatorship,” Cox said. “No president should be able to undo a law he doesn’t like through administrative fiat.”

The White House referred questions about the case to the Justice Department, which declined to comment.

The restriction on what is known as “official time” — which will ultimately have to be bargained through collective bargaining contracts at federal agencies — was one of three orders the president signed late Friday before the Memorial Day weekend to roll back long-held civil service protections for federal employees.

Under official time, federal employees who also serve as union officials are permitted to work on-duty time to represent employees who have filed grievances claiming unfair labor practices by management or who are appealing disciplinary action against them.

These officials, who spend anywhere between half and all of their time working on union matters, also negotiate collective bargaining agreements. Their responsibilities are limited to representing employees in the workplace and do not include internal union business, such as collecting dues, soliciting membership or elections.

The other executive orders Trump signed instruct agencies to crack down on unions in contract negotiations — with the goal of less union-friendly agreements — and to move more aggressively to fire employees with records of misconduct or poor performance.

Administration officials say these changes, which build on successful efforts in several states to weaken public employee unions, will make government smaller and more efficient by weeding out bad apples and rewarding employees who play by the rules.

But the most controversial change has turned out to be to the official time guarantee that Congress gave federal employee unions four decades ago. That guarantee allowed union representatives to use some of their work time to negotiate for workers on everything except pay, which is determined by Congress through the General Schedule.

Conservatives in Congress have tried unsuccessfully for years to restrict official time. The administration, which says the work of public employee unions should not be heavily subsidized by taxpayers, estimates that reducing the practice to 25 percent will save taxpayers as much as $100 million a year.

AFGE, which represents about 700,000 federal workers, argues in its lawsuit that the Trump administration has violated the union’s right to freedom of association, guaranteed by the First Amendment. The lawsuit claims the administration has singled out labor organizations for disparate treatment.

The union is using language from the executive order to make its point: The order prohibits union employees from using official time to represent other federal workers in grievance or disciplinary proceedings, but it provides an exception for employees working on their own cases.

“There is no valid basis to distinguish grievances brought by the union [on behalf of the] union or grievances in which a union representative seeks to represent another employee from grievances brought on an employee’s own behalf or instances in which an employee is to appear as a witness in a grievance proceeding,” the lawsuit says.

By singling out unions for what it calls “disparate treatment,” the lawsuit says the executive order “unlawfully restrains and retaliates against AFGE and its union-member representatives, separately and collectively, in and for the exercise of their rights to expressive association.”

AFGE also says that mandating the number of hours agencies may authorize for employees’ use of official time to 25 percent illegally changes a provision of the law Congress passed in 1978 — the Civil Service Reform Act — that governs collective bargaining and determines that official time is lawful.

“Congress passed these laws to guarantee workers a collective voice in resolving workplace issues and improving the services they deliver to the public every day — whether it’s caring for veterans, ensuring our air and water are safe, preventing illegal weapons and drugs from crossing our borders, or helping communities recover from hurricanes and other disasters,” Cox said.

“We will not stand by and let this administration willfully violate the Constitution to score political points.”

Leaders of the National ­Treasury Employees Union, the ­second-largest federal labor organization, with about 150,000 members, said they are still studying what the executive orders mean for existing collective bargaining contracts , weighing legal action and communicating with their members.

“Our basic message [to our members] is that the administration has made it very clear they think federal workers are dispensable, that they don’t respect and value front-line employees,” said Tony Reardon, the NTEU’s national president.