Is there any law which prohibits foreigners (non-US citizens) from spending billions of dollars to sway U.S. elections by deliberately placing attack ads against certain political parties ? Can foreigners join super PACS ?
TL;DR: Foreign nationals wanting to have an impact on US elections should get permanent residency (a "green card") or support 527 organizations.
The Federal Election Campaign Act
Yes, there is a law that regulates political spending and fundraising in the United States. It's called the Federal Election Campaign Act.
You're using the term "non-US" citizen. However, the law uses the term "foreign national", which doesn't apply to all non-US citizens (see definition below).
For example, if the non-US citizen has a "green card", then that person is not considered a foreign national and can legally spend his/her money on political causes in the US.
The [Federal Election Campaign] Act does not prohibit individuals with permanent resident status (commonly referred to as “green card holders”) from making contributions or donations in connection with federal, state or local elections, as they are not considered foreign nationals.
However, in all other cases, non-US citizens are considered foreign nationals and are prohibited from making political contributions.
In general, foreign nationals are prohibited from the following activities:
Making any contribution or donation of money or other thing of value, or making any expenditure, independent expenditure, or disbursement in connection with any federal, state or local election in the United States;
Making any contribution or donation to any committee or organization of any national, state, district, or local political party (including donations to a party nonfederal account or office building account);
Making any disbursement for an electioneering communication;
Making any donation to a presidential inaugural committee.
The definition of "foreign national", per the Federal Election Campaign Act:
The following groups and individuals are considered "foreign nationals" and are subject to the prohibition:
Foreign citizens (not including dual citizens of the United States);
Immigrants who are not lawfully admitted for permanent residence;
Foreign political parties;
Foreign partnerships; and
Any other foreign principal, as defined at 22 U.S.C. § 611(b), which includes a foreign organization or “other combination of persons organized under the laws of or having its principal place of business in a foreign country.”
Only American citizens (and immigrants with green cards) can contribute to federal politics, but the American divisions of foreign companies can form political action committees (PACs) and collect contributions from their American employees.
A 527 is a non-profit organization that can engage in general political activities. It is prohibited from direct involvement with political candidates, but it can engage in such things as issue advocacy and "get-out-the-vote" efforts. Hence, 527s are not subject to the Federal Election Campaign Act and don't report to the Federal Election Commission. (They report to the Internal Revenue Service.) There is no prohibition on foreign contributions.
I want to point out that the Supreme Court's Citizens United ruling has turned the previously strict barrier preventing foreign nationals from donating to US political campaigns into a virtual sieve.
The law says that any foreign national is prohibited from "directly or indirectly" contributing money to influence US elections. But the law is not quite as clear on how to treat US subsidiaries of foreign companies (even owned wholly by foreign nationals). As one such example, "reinsurance company OdysseyRe of Conn., a 'wholly-owned subsidiary' of Canadian insurance and investment management giant Fairfax Financial Holdings Limited", made a $1 million contribution to Mitt Romney's Super PAC Restore Our Future.
Furthermore, while US individuals are still capped at $2700 per person per election cycle, corporations are allowed unlimited donations, publicly disclosed, to any Super PAC, and unlimited donations, not publicly disclosed, to any politically active nonprofit, such as Karl Rove's Crossroads GPS. Crossroads GPS was well known for the huge amount of money they spent on attack ads against Obama.
So to answer your questions, foreign nationals can't directly contribute to Super PACs, but Citizens United has created some glaring loopholes for foreign nationals (with US subsidiary companies) to contribute to political causes without even having to publicly disclose such donations.