The House on Thursday passed a bill reauthorizing a key intelligence tool that helps US spies keep tabs on foreign terrorists — hours after President Trump sent out two tweets, one suggesting he was against the measure, the other declaring he was all for it.

The bill renews a section of the Foreign Intelligence Surveillance Act, giving the feds the authority to continue conducting warrantless surveillance of foreign targets.

The vote came after Trump’s apparently contradictory tweets.

“’House votes on controversial FISA ACT today.’ This is the act that may have been used, with the help of the discredited and phony Dossier, to so badly surveil and abuse the Trump Campaign by the previous administration and others?” he tweeted at 7:33 a.m., following a cry against the bill by someone on his favorite cable show, “Fox & Friends.”

Then, at 9:14 a.m., after a phone conversation with House Speaker Paul Ryan, the president issued another tweet that more accurately reflected his administration’s position on the bill, which he previously said he supported.

“With that being said, I have personally directed the fix to the unmasking process since taking office and today’s vote is about foreign surveillance of foreign bad guys on foreign land. We need it! Get smart!” Trump wrote.

Administration spokeswoman Sarah Huckabee Sanders said it was “ridiculous” to suggest that the tweets were contradictory or inspired by Fox News.

“We don’t think there was a conflict at all. The president fully supports the [act] and [was] happy to see it passed the House today but does have some overall concern with the FISA program more generally. We don’t see any contradiction or confusion in that,” she said.

The FISA bill will now go to the Senate, which is expected to pass the measure before the program’s Jan. 19 expiration date.

The law would give the feds another six years to gather ­e-mails and other communications of foreign targets.

With Post wires