About 58% of men convicted in Sweden of rape and attempted rape over the past five years were born abroad, according to data from Swedish national TV.
Public broadcaster SVT said it had counted all court convictions to present a complete picture in Sweden.
But Sweden had thousands more reported rapes, and there is no ethnic breakdown for those.
Immigration and crime are major issues in Sweden's general election campaign. The vote is on 9 September.
The anti-immigration Sweden Democrats hope to make significant ground, although they have slipped to third place in the latest opinion poll.
The Mission Investigation programme, due to be broadcast on Wednesday by SVT, said the total number of offenders over five years was 843. Of those, 197 were from the Middle East and North Africa, with 45 coming from Afghanistan.
"We are very clear in the programme that it is a small percentage of the people coming from abroad who are convicted of rape," chief editor Ulf Johansson told the BBC.
He pointed out that the number of reported rapes in Sweden was far higher, so no conclusions could be drawn on the role of immigrants in sexual attacks.
When Sweden took in its highest number of asylum seekers in 2015, the number of reported rapes declined by 12%. At the height of the migration crisis, some 160,000 migrants arrived there - more per capita than any other EU country.
The steep rise in migration also raised questions about Sweden's ability to integrate immigrants. The centre-left Social Democrat-led government soon introduced restrictions and the number of arrivals fell dramatically.
The SVT programme revealed that in cases where the victim did not know the attacker, the proportion of foreign-born offenders was more than 80%.
A former police officer born in Afghanistan told the programme that some young Afghans who had come to Sweden in recent years had views that differed significantly from Sweden's idea of sexual equality.
Responding to the report on Wednesday, key figures in both the populist Sweden Democrats (SD) and the centre-right Moderates said foreigners convicted of rape should be deported.
The latest opinion poll on Wednesday suggests the populist party's support has dipped in recent weeks to just over 19% in the polls, but it is still on course for its best performance yet. The Social Democrats are leading the polls while the Moderates are just ahead of the anti-immigration SD.
When asked why SVT had decided to produce a potentially inflammatory programme ahead of the election, Ulf Johansson stressed that every political party was tackling issues around immigration and it was important to give Swedes a better insight into their society.
"I don't think this will have an effect on the election," he said. "There has been a lot of debate already about this and it's just more facts in an existing debate."
In May, Sweden changed its laws, to make sex without consent rape. Until then prosecutors had to prove that violence had been used or the victim had been exploited in a vulnerable condition.