The Ukrainian parliament has approved a bill that effectively rejects any ambition to join Nato.
The law, submitted by President Viktor Yanukovych, cements Ukraine's status as a military non-aligned country - though it will co-operate with Nato.
President Yanukovych was elected earlier this year, vowing to end Ukraine's Nato membership ambitions and mend relations with Russia.
His predecessor, Viktor Yushchenko, had pursued a pro-Western foreign policy.
Under him, relations with Moscow had declined dramatically, with the Kremlin refusing to talk to him.
Since his February inauguration, Mr Yanukovych has wasted no time in re-shaping Ukraine's foreign policy in a more Moscow-friendly way, the BBC's David Stern in Kiev says.
In April, he agreed to extend the lease allowing Russia's Black Sea fleet to be stationed in the southern port of Sevastopol by 25 years in return for cheaper gas.
An extension of the lease, due to expire in 2017, had been opposed by Mr Yushchenko.
Moscow had made known its opposition to Ukraine's plans to join Nato, and opinion polls indicate the majority of Ukrainians opposed Nato membership too, our correspondent reports.
The new bill bars Ukraine's membership in any military bloc, but allows for co-operation with alliances such as Nato.
"The main element of predictability and consistency in Ukraine's foreign policy is its non-aligned status," Prime Minister Mykola Azarov said as he submitted the bill.
However, the new law will not affect Ukraine's political and economic integration with Europe.
Joining the European Union remains a priority, Mr Azarov said.