BANGOR, Maine — A Sedgwick man was sentenced Monday at the Penobscot Judicial Center to four years in prison for having sex more than three years ago with a 15-year-old girl he met online.

Patrick Gaffney-Kessell, 29, will serve the state sentence at the same time he is serving 6½ years in federal prison for traveling from Maine to Pennsylvania more than two years ago to have sex with a 13-year-old girl he’d met online.

Gaffney-Kessell pleaded guilty Monday to one count of sexual abuse of a minor in state court after being sentenced Friday in U.S. District Court on the federal charge.

Michael Roberts, deputy district attorney for Penobscot County, told Active Retired Superior Court Justice Donald Marden that Gaffney-Kessell met his then-15-year-old victim, who lived in the Bangor area, online. She agreed to meet him, the prosecutor said Monday.

Gaffney-Kessell met the girl on Nov. 1, 2010, then, drove her in his car to an area behind a restaurant in the Hogan Road area of Bangor and had sex with her, Roberts said. Because of the girl’s age and the fact that Gaffney-Kessell was more than 10 years older than she was, he was charged with a felony.

He was indicted in June 2012 by the Penobscot County grand jury on the sexual abuse charge, a Class C crime. In a plea agreement with Roberts Gaffney-Kessell pleaded guilty and was sentenced Monday.

Gaffney-Kessell waived indictment in February and pleaded guilty in federal court to one count of travel with intent to engage in criminal sexual activity in January 2011 in connection with the crime against the then-13-year-old Pennsylvania girl.

He had been held without bail since then.

Gaffney-Kessell’s convictions in state and federal court will require him to register as a sex offender for life after he is released from prison.

In addition to prison time, U.S. District Judge John Woodcock sentenced Gaffney-Kessell to five years of supervision after his release from federal prison.

Gaffney-Kessell and the then-13-year-old victim, who is referred to as Jane Doe in court documents, began communicating online in the fall of 2010.

“The defendant and Jane Doe traded multiple text messages, Facebook chats, emails and phone calls between October of 2010 and January of 2011,” according to the prosecution version of events to which Gaffney-Kessell pleaded guilty. “During these communications, Jane Doe informed the defendant that she was only 13 years old.”

He posted photos of himself naked to the girl’s Facebook page, the document said. Gaffney-Kessell also told her the kind of sexual activity he want to engage in with her.

On Jan. 12, 2011, Gaffney-Kessell drove 10-12 hours from Maine to the town where the girl lived, which is not identified in court documents. He rented a motel nearby but the girl refused to meet him.

“When Jane Doe refused to go to the hotel, the defendant became frustrated, drove to Jane Doe’s house and walked in front of the house,” the prosecution version of events said. “Jane Doe became afraid and asked the defendant to leave.”

On the federal charge, he faced up to 30 years in prison and a fine of up to $250,000. Under the prevailing federal sentencing guidelines, the recommended sentence was between 6½ years and eight years and one month.

Gaffney-Kessell faced up to five years in prison a fine of up to $10,000 on the state charge.