Aberdeen won at Rangers for the first time since 1991, while St Johnstone defeated Hearts and Inverness boosted their survival chances in the Scottish Premiership.