It's an old tune. The Scots claim it is based on a carol of 1611 called Remember O thou Man or Franklyn is fled away of 1669. It has also been traced to Purcell in 1696.
God Save the King was used as a naval watchword to which the reply was Long to reign over us.
For a long time the song was used as an expression of personal loyalty to the king and in translation it was used in Prussia, Denmark, and in Russia until 1833 when Tsar Nicholas commissioned a new version. The tune has also been used in Sweden, Switzerland, Liechtenstein and the United States.