SHORT ANSWER: These are Harold B. Lee's words based on John Taylor's extrapolation of Brigham Young's and Orson Hyde's expression of an idea originating with Joseph Smith.
LONG ANSWER: Joseph Smith gave a talk on 19 July 1840. The only known journal account of this speech was made by Martha Jane Knowlton. Her journal did not surface publicly until the 1970's. She records The Prophet saying,
"Even this nation will be on the very verge of crumbling to pieces and tumbling to the ground; and when the Constitution is upon the brink of ruin, this people will be the staff upon which the nation shall lean; and they shall bear the constitution away from the very verge of destruction. " [spelling and punctuation modernized] (Dean C. Jessee, "The Historian's Corner" BYU Studies Vol. 19, No. 3, Spring 1979, p. 392)
Until the 1970's the only published accounts of the speech were given by Brigham Young and Orson Hyde, 14 and 18 years after the fact, respectively.
"Will the Constitution be destroyed? No; it will be held inviolate by this people; and, as Joseph Smith said, 'The time will come when the destiny of the nation will hang upon a single thread. At that critical juncture, this people will step forth and save it from the threatened destruction.' It will be so." (JD 7:15, Brigham Young, 4 July 1954)
"It is said that brother Joseph in his lifetime declared that the Elders of this Church should step forth at a particular time when the Constitution should be in danger, and rescue it, and save it. This may be so; but I do not recollect that he said exactly so. I believe he said something like this--'that the time would come when the Constitution and the country would be in danger of an overthrow; 'and said he, 'If the Constitution be saved at all, it will be the Elders of this Church.' I believe this is about the language, as nearly as I can recollect it." (JD 6:152, Orson Hyde, 3 January 1858)
Joseph Smith also gave a speech on 6 May 1843 to the Navuoo Legion. Three contemporary accounts of this speech (Willard Richards, Levi Richards, and the Navuoo Neighbor ) do not record Joseph saying anything about the constitution, but an unpublished account written many years later by James Burgess claims Joseph to have said:
"Also upon the constitution and government of the United States stating that the time would come when the Constitution and Government would hang by a brittle thread and would be ready to fall into other hands but this people the Latter day Saints will step forth and save it." (James Burgess Notebook, Church Archives, as cited in Andrew Ehat and Lyndon Cook (1980) The Words of Joseph Smith . SLC, Utah: Bookcraft.)
Publicly, Brigham Young gives us the 'hang by a thread' phrase. It is not clear to me whether Brigham's public statement was based on Burgess's private account, or if Burgess's private account is using Brigham's language. I suspect the latter because it seems that Burgess is remembering two different speeches (1840 and 1843) as if they were one speech and mixing what was said.
Orson Hyde is the first to say it is the Elders--in contrast to the Mormon People--who will save the Constitution. Moreover, Brigham Young's paraphrase said the nation (not constitution) will hang by a thread. Some 25 years after Brigham's public statement, John Taylor, building mostly on the Orson Hyde account, stands the doctrine up by itself without reference to Joseph Smith.
"When the people shall have torn to shreds the Constitution of the United States the Elders of Israel will be found holding it up to the nations of the earth and proclaiming liberty and equal rights to all men, and extending the hand of fellowship to the oppressed of all nations." (JD 21:8, John Taylor, 31 August 1879)
Since John Taylor, a number of church authorities--including Joseph F. Smith, Charles Penrose, J. Reuben Clark, and Joseph Fielding Smith--talked about [either the constitution or the nation] [either hanging by a thread or being torn to shreds] and [either the Saints or the Elders] saving the constitution. The first one to use all three images (hanging thread, constitution, and Elders) simultaneously in a single sentence was Harold B. Lee in 1952.
"It was Joseph Smith who has been quoted as having said that the time would come when the Constitution would hang as by a thread and at that time when it was thus in jeopardy, the elders of this Church would step forth and save it from destruction." (Harold B. Lee, Conference Report, October 1952, p.18.)
This particular phraseology was then picked up and popularized primarily by Ezra Taft Benson and Ernest L. Wilkinson during the 1960s. Since the 1960s, this phraseology has been repeated by numerous church authorities in a variety of publications.