PORTLAND, Maine — A serial rapist from Massachusetts who spent 34 years as a fugitive before he was caught in Maine last year, admitted Thursday in federal court that he is guilty of identity theft and being a felon in possession of guns.

Gary Alan Irving, 53, who was sentenced to nearly four decades behind bars in May 2013 for three 1979 rapes in the Bay State, was returned to Maine in February to face three felony charges stemming from his time in the state living under an assumed name.

He initially entered not guilty pleas before a U.S. district judge to the aggravated identity theft, being a felon in possession of firearms and social security fraud charges. He changed two of those pleas on Thursday, and the third charge is still pending. He is expected to be sentenced in June for the two crimes to which he admitted he was guilty.

When police arrested Irving in March 2013, they found four rifles, four shotguns and a .22-caliber six-shooter when they searched his Gorham home, the federal indictment filed in December states.

Two months after his capture in Maine, Irving was returned to the same Dedham, Mass., courtroom that he fled three decades before and was sentenced to two consecutive 18- to 20-year terms in state prison.

Irving was supposed to be sentenced June 27, 1979, after he was convicted of raping three 16-year-old girls in Weymouth, Cohasset and Holbrook. Instead, he fled.

He ended up in Maine living under the name Gregg Irving.

He was Massachusetts State Police’s longest-wanted fugitive.