Matthew Shepard has been laid to rest at the Washington National Cathedral, 20 years after he was brutally beaten and killed because of his sexuality.

The first openly gay Episcopal bishop, Gene Robinson, presided.

The men responsible for his 1998 murder admitted targeting Shepard because he was gay. His death is remembered as one of the worst US anti-gay hate crimes.

In 2009, Congress passed the Matthew Shepard Act, expanding hate crime laws to include sexual orientation.

After the public service, attended by hundreds, Shepard's ashes were formally interred in a smaller, private ceremony.

He is one of about 220 Americans interred in the capital's cathedral, including former US President Woodrow Wilson and Helen Keller.

The Bishop of Washington, Reverend Mariann Edgar Budde, also presided over the ceremony alongside the now-retired Rev Robinson of New Hampshire.

The service included music by the Gay Men's Chorus of Washington DC, LGBT youth chorus group GenOUT and Conspirare, a Grammy-award winning group that created music inspired by Shepard.

Rev Robinson, who was consecrated five years after Shepard's death, became a friend of the Shepard family, and it was through him that the National Cathedral internment process began.

"Let me just say I've been crying for a week now, so I'm pretty apt to cry during this sermon," Rev Robinson said in his opening remarks.

"Matt was luckier than most young gay men in 1998," he continued.

"He had parents and a brother who loved him. He loved his church, the Episcopal church, and they loved him back. And I have no doubt that Matt is in heaven."

On Tuesday 6 October, 1998, in Laramie, Wyoming, two men attacked Shepard, a 21-year-old openly gay university student.

They pistol-whipped him repeatedly before tying him to a fence and leaving him for dead.

Shepard soon became an internationally known symbol of the violence LGBT people face.

His death, along with the horrific murder of James Byrd Jr, a black man killed by white supremacists that same year, eventually led to the US government addressing gaps in federal hate crime law.

President Barack Obama signed the Matthew Shepard and James Byrd Jr Hate Crimes Prevention Act into law on 28 October, 2009, expanding federal law to count crimes motivated by a victim's sexual orientation, gender or disability as hate crimes.

But some still contest whether Shepard's murder was a hate crime, and Wyoming is one of five US states that still have no criminal hate crime laws.

"The bigger picture here is what we human beings tend to do, which is to label someone different from ourselves as 'other', which is code for 'not really human'," Rev Robinson said during the service.

"People of colour know that. The LGBTQ community knows that. Every marginalised person and group in this country knows that. And we are seeing way too much of that at the moment."

Shepard's interment comes as the Trump administration is considering redefining gender as the genitalia one is born with. Doing so would affect around 1.4m transgender people in the US.