HONG KONG—The government of Hong Kong agreed to grant dependency visas to foreigners in same-sex unions, in a step toward greater recognition of gay rights that was long sought by multinational companies operating in the Chinese financial center.

The government made the change, which takes effect on Wednesday, after the city’s highest court ruled in July that immigration officials were wrong to deny a dependency visa to a British lesbian whose partner was offered work in the city. More than a dozen banks and law firms—including...