Media playback is unsupported on your device Media caption Former President Jimmy Carter and Aijalon Mahli Gomes leave North Korea

Former US President Jimmy Carter has secured the release of an American citizen detained in North Korea.

Aijalon Mahli Gomes, 31, was sentenced to eight years' hard labour in April, after being found guilty of illegally entering the country from China.

Mr Carter, who spent two days in Pyongyang, has now left with Mr Gomes.

North Korea's state media said officials told Mr Carter of Pyongyang's willingness to re-enter talks on its nuclear programme.

The North's Deputy Prime Minister Kim Yong-nam "expressed the Republic's commitment to denuclearise the Korean peninsula and resume the six-way talks," the North Korean Central News Agency (KCNA) said.

Mr Carter is flying to Boston with Mr Gomes, where he will be reunited with his family later on Friday.

Stalled talks

Mr Carter met senior North Korean officials after arriving in Pyongyang on Wednesday on what was described as "a private humanitarian trip".

On his arrival, Mr Carter was met by North Korea's nuclear negotiator, Kim Kye-gwan, KCNA said.

Later he held "cordial" talks with the country's deputy leader, Kim Yong-nam, the agency said.

Image caption Jimmy Carter flew into Pyongyang on a private mission

Six-nation talks aimed at ending North Korea's nuclear ambitions have been stalled for several months.

Mr Carter's visit comes at a time of heightened tension between North Korea and the outside world, in the wake of the sinking of a South Korean warship.

International investigators say a North Korean torpedo sank the Cheonan, which went down near the disputed inter-Korean border on 26 March with the loss of 46 sailors.

Since then, the US and South Korea have embarked on a series of joint military exercises - sparking an angry response from Pyongyang.

South Korea refuses to re-enter new talks until it has secured an apology from the North for the ship sinking - something North Korea has refused to offer as it denies any role in the incident.

But North Korea has come under pressure from Beijing to rejoin the talks.

One-man mission

Mr Gomes, a devout Christian who had entered North Korea in January, had been teaching English in South Korea.

He reportedly crossed into North Korea in January. He is thought to have gone there on a one-man peace mission.

Pastor Simon Suh at the Every Nation Church of Korea which Mr Gomes attended in Seoul said he had no idea he was planning the trip.

"He was a gentle and spiritual man," Pastor Suh told the BBC's World Today programme, adding that North Korean refugees Mr Gomes met at the church would have given him reports of the lack of religious freedom in the North.

Pastor Suh said members of church "felt like their prayers were answered" when they heard about Mr Gomes release.

He had been visited by a US official and two doctors in a hospital in Pyongyang earlier this month. North Korea said in July that Mr Gomes had tried to commit suicide.

A spokeswoman for Mr Carter said Mr Gomes was expected to be back in his hometown of Boston by Friday afternoon.

In visiting North Korea, Mr Carter is following in the footsteps of another former US President, Bill Clinton, who last year secured the release of two US journalists detained in North Korea for crossing the border.

The journalists, Laura Ling and Euna Lee, were pardoned and returned to the US with Mr Clinton.