BERWYN, Pa. — Melania Trump made a rare appearance on the campaign trail in the battleground state of Pennsylvania on Thursday, seeking to soften her husband’s coarse image by proclaiming to voters that Donald J. Trump respects all Americans and promising that as president he would promote values of compassion and charity across the country.

The deployment of Ms. Trump comes as her husband’s campaign is trying to extend a late burst of momentum before Election Day by swaying undecided voters and women who have been wary of the Republican nominee. Urging Americans to “find a better way to talk to each other” amid one of the most caustic presidential campaigns in recent history, Ms. Trump cast immigrants as patriots and lamented, in spite of her husband’s tough talk on Twitter, cyberbullying as one of the country’s worst problems.

Mr. Trump needs the trove of wealthy and educated voters in the counties surrounding Philadelphia to succeed in turning the state red for the first time since 1988, but many of those former Republicans have been turned off by his comments about immigrants and women.