Two German tourists have been killed and four other foreigners were wounded when an assailant stabbed them at an Egyptian Red Sea beach resort, officials said.

Germany's foreign ministry confirmed on Saturday that the two women killed in the attack in Hurghada were German nationals.

Egypt's interior ministry said the assailant was arrested immediately on Friday and that a motive was still under investigation.

The attacker had swum from a nearby public beach to access the holiday resort, the ministry said.

A security official said the attacker, a man in his 20s who was dressed in a black T-shirt and blue jeans, wielded a knife and intentionally sought to attack foreigners.

READ MORE: Gunmen kill five Egyptian policemen near Cairo

He shouted in Arabic during the attack: "Stay away, I don't want Egyptians."

He stabbed the tourists in the face, neck and feet.

According to AFP news agency, the attack happened at Sunny Days El Palacio hotel.

All of the victims were reported to be women.

An Armenian foreign ministry spokesman said two Armenian women had been wounded in the attack, and the Czech foreign ministry tweeted that one of its nationals had been lightly injured.

Hurghada is one of Egypt's most popular beach resorts, especially with Ukrainians and European tourists.

A similar attack took place in Hurghada in January 2016 when two attackers armed with a gun, a knife and a suicide belt landed on the beach of a hotel, wounding two foreign tourists, according to security sources.

Also on Friday, unknown assailants shot dead five policemen south of Cairo, in the latest of a series of attacks targeting the country's security forces.