The 81-year-old Museveni, in power since 1986, has over the years regularly decried outside influence in Uganda, accusing domestic political rivals of receiving funding from abroad.
Museveni signed the legislation, effectively making it law, his office said in a statement issued late on Sunday.
The "Protection of Sovereignty" bill, passed this month, criminalises promotion of the "interests of a foreigner against the interests of Uganda" and requires foreign agents to register.
It also bans anyone working on behalf of foreign interests from developing or implementing policy without government approval.
Penalties for violations include up to 10 years in prison and steep cash fines.
Central Bank governor Michael Atingi-Ego warned the law could diminish financial flows into Uganda and risked running down foreign exchange reserves, in a situation he called an "economic disaster for our country".
The World Bank also criticised the legislation, saying it could expose to criminal liability a broad range of "routine development activities".
(Editing by Vincent Mumo Nzilani and Clarence Fernandez)

A young person (C) takes a bath using a jerrycan outside their house in the Kitintale slum area of Kampala, Uganda, 19 January 2026. The Ugandan Electoral Commission declared incumbent Yoweri Museveni president-elect after elections held on 15 January 2026. EPA/DANIEL IRUNGU