Matthias O. Imregh, 91, a Washington librarian who survived two world wars in his native Hungary and lost everything but his family and his principles as he escaped the communist takeover in 1956, died May 31 at Manorcare Potomac of complications from a series of strokes that began in 1986.

Mr. Imregh, who was born in Pecel, Hungary, 20 miles from Budapest, was a criminal court judge of the Hungarian royal government between the world wars.

He had received a doctorate in law from Pazmany Peter University in Budapest in 1937.

After World War II, when Hungary fell under the aegis of the Soviet Union, Hungarian law became unacceptable to the new overseers, and Mr. Imregh was deposed from the bench.

Mr. Imregh earlier had studied at Innsbruck, in Austria, with the Jesuits. During his two years there, he refined the sort of character with which he was to face the days ahead.

"A good judge," said his wife of 50 years, Anna Maria Szalkay Imregh, "is not too far from a good priest."

He learned Latin, and in later years carried a Latin breviary from which he read.

He also spoke Greek, Hungarian and German, and later, after six months in the United States and a six-month course at Georgetown University, fluent English.

As Soviet tanks rumbled through the streets during the Hungarian revolution of 1956, Mr. Imregh, who had been supporting his wife and daughter by manual labor--including laying bricks and digging ditches--knew it was time to go.

He had been active in an underground group, and on Aug. 6, 1956, he was arrested. Briefly released while the communist government was shuffling policies, Mr. Imregh escaped through the mountains with his family to Austria.

There, other resistance groups greeted them and offered alternate destinations as havens, and Mr. Imregh chose the United States.

In Washington as a refugee, Mr. Imregh was offered the opportunity to get a new law degree, but he found the difference between English common law and the old Hungarian law far too different for his training, his tastes and his principles, so he opted for a master's degree in library science at Catholic University in 1962.

He worked for the D.C. Public Library from 1959 until his retirement in 1978, as chief of the philosophy department.

Survivors include his wife; and his daughter, Agnes Elizabeth Imregh, of Palo Alto, Calif.