WASHINGTON — On a trip to Ireland in 1998, Speaker Newt Gingrich researched his Irish roots, discussed the prospects for peace in Northern Ireland and entertained speculation about his presidential ambitions. He even donned work gloves and blue jeans to help build a home in Belfast for a good-will project.

Two of the sponsors for part of the Ireland trip were frequent partners of Mr. Gingrich: Freddie Mac and Fannie Mae — the government-backed housing industry giants that Mr. Gingrich has denounced as he fights to stay in contention against Mitt Romney in the Republican primaries.

Mr. Gingrich has faced many questions recently about the more than $1.6 million in consulting fees he got from Freddie Mac since leaving Congress in 1999. But part of the relationship started years earlier, as records and interviews show that Mr. Gingrich, as House leader in the 1990s, aligned himself with Freddie and Fannie on a number of key issues — defending them in Congress against political attacks, joining with them on housing projects and seeing top aides go work for them.

While Mr. Gingrich has minimized his past connections to the two closely related companies on the campaign trail, his Congressional record shows that his political and financial ties to the firms run deeper and farther back than he has acknowledged publicly and, in fact, set the stage for the lucrative consulting work that followed.