HANOI—Vietnam has moved to allow foreigners to buy homes as it tries to revive its struggling real-estate market and attract more outside investment.

Foreign organizations and companies operating in the country, as well as foreign individuals with valid visas, will be able to buy houses and apartments, according to Phan Trung Ly, head of the National Assembly’s Law Committee. The National Assembly overwhelmingly passed the legislation Tuesday, and President Truong Tan Sang is expected to sign it. The measure will take effect...