WASHINGTON — Erik Prince, the security contractor with close ties to the Trump administration, has in recent years helped recruit former American and British spies for secretive intelligence-gathering operations that included infiltrating Democratic congressional campaigns, labor organizations and other groups considered hostile to the Trump agenda, according to interviews and documents.

One of the former spies, an ex-MI6 officer named Richard Seddon, helped run a 2017 operation to copy files and record conversations in a Michigan office of the American Federation of Teachers, one of the largest teachers’ unions in the nation. Mr. Seddon directed an undercover operative to secretly tape the union’s local leaders and try to gather information that could be made public to damage the organization, documents show.

Using a different alias the next year, the same undercover operative infiltrated the congressional campaign of Abigail Spanberger, then a former C.I.A. officer who went on to win an important House seat in Virginia as a Democrat. The campaign discovered the operative and fired her.

Both operations were run by Project Veritas, a conservative group that has gained attention using hidden cameras and microphones for sting operations on news organizations, Democratic politicians and liberal advocacy groups. Mr. Seddon’s role in the teachers’ union operation — detailed in internal Project Veritas emails that have emerged from the discovery process of a court battle between the group and the union — has not previously been reported, nor has Mr. Prince’s role in recruiting Mr. Seddon for the group’s activities.