(Solution by Bill Duke) Before any weighing takes place you know:

Either you have five genuine gold bars each weighing the same or you have four genuine gold bars each weighing the same and one counterfeit bar that weighs either more or less than a genuine gold bar.

Arbitrarily select and weigh two bars and call the sum of their weights "w1". From the remaining three bars select and weigh two more bars and call the sum of their weights "w2".

You have already used up two of your three weighings and the king is watching you. Proceed with caution.

If w1 equals w2, select and weigh the remaining fifth bar and call its weight "w3". If w3 equals one half of w1, all five bars are genuine and each weighs w3. However, if w3 does not equal one half of w1, the fifth bar selected weighing w3 is counterfeit and the other four bars each weighing one half of w1 are genuine.

If w1 does not equal w2, the unweighed fifth bar is genuine but one of the four previously weighed bars is counterfeit. Select and weigh these three bars: the unweighed fifth bar, one of the two bars in w1, and one of the two bars in w2. Call their combined weight "w4". (Many former subjects of the king have failed to include the unweighed but genuine fifth bar in w4, a fatal mistake.)

At this point you know:

If the counterfeit bar is in w1, the genuine bars each weigh one half of w2 and the counterfeit bar weighs w1 less one half of w2.

If the counterfeit bar is in w2, the genuine bars each weigh one half of w1 and the counterfeit bar weighs w2 less one half of w1.

If the counterfeit bar is not in w4, w4 is equal to three times the weight of a genuine bar.

If the counterfeit bar is in w4, w4 is equal to the weight of the counterfeit bar plus two times the weight of a genuine bar.

Rearranging this information you can with confidence tell the king:

If w4 equals w1 plus one half of w2, the counterfeit bar is in both w1 and w4, the counterfeit bar weighs w1 less one half of w2, and each of the other four genuine bars weighs one half of w2.

If w4 equals w2 plus one half of w1, the counterfeit bar is in both w2 and w4, the counterfeit bar weighs w2 less one half of w1, and each of the other four genuine bars weighs one half of w1.

If w4 equals one and one half times w2, the counterfeit bar is in w1 but not in w4, the counterfeit bar weighs w1 less one half of w2, and each of the other four genuine bars weighs one half of w2.

If w4 equals one and one half times w1, the counterfeit bar is in w2 but not in w4, the counterfeit bar weighs w2 less one half of w1, and each of the other four genuine bars weighs one half of w1.

The king is so pleased you have solved the puzzle in only three weighings that he has spared your life. (This is so you may live to attempt solving another puzzle on some day.)