Madrid stated that the proposal posed "insurmountable risks" to public order, and classified the informational part of the application as secret.
Budapest-based Ganz-Mavag called the decision "arbitrary" for a non-strategic company without technology that could affect national security.
The Spanish government's decision ended a controversial attempt by a Hungarian conglomerate to take control of the train manufacturer.
Ganz-Mavag is owned by a private investment fund managed by the state-owned oil company Mol Nyrt, whose leadership is connected to Hungarian Prime Minister Viktor Orbán.
The failed deal highlights political tensions within the European Union, where Orbán has been accused of fostering nepotism and corruption. Hungary, which currently holds the rotating EU Council presidency, has openly opposed EU aid to Ukraine.
In March, Ganz-Mavag offered 619 million euros to acquire the Spanish firm Talgo. The Czech company Skoda Transportation also approached Talgo with a proposal for a "business combination," but the Spanish company's board of directors rejected it.
Previously, the U.S. imposed sanctions on two Hungarian entities for supporting Russia's aggression against Ukraine.