By use of the threshold expansion we develop an algorithm for analytical evaluation, within dimensional regularization, of arbitrary terms in the expansion of the (two-loop) sunset diagram with general masses mi, mt and m(3) near its threshold, i.e. in any given order in the difference between the external momentum squared and its threshold value, (m(1) + m(2) + m(3))(2). In particular, this algorithm includes an explicit recurrence procedure to analytically calculate sunset diagrams with arbitrary integer powers of propagators at the threshold. (C) 1999 Published by Elsevier Science B.V, All rights reserved.