Supervised learning methods based on convolutional neural networks (CNNs) show promising performance in several medical image analysis tasks. Such performance, however, is marred in the presence of acquisition-related distribution shifts between training and test images. Recently, it has been proposed to tackle this problem by fine-tuning trained CNNs for each test image. Such test-time-adaptation (TTA) is a promising and practical strategy for improving robustness to distribution shifts as it requires neither data sharing between institutions nor annotating additional data. Previous TTA methods use a helper model to increase similarity between outputs and/or features extracted from a test image with those of the training images. Such helpers, which are typically modeled using CNNs and trained in a self-supervised manner, can be task-specific and themselves vulnerable to distribution shifts in their inputs. To overcome these problems, we propose to carry out TTA by matching the feature distributions of test and training images, as modelled by a field-of-experts (FoE) prior. FoEs model complicated probability distributions as products of several simpler expert distributions. We use the 1D marginal distributions of a trained task CNN's features as the experts in the FoE model. Further, we carry out principal component analysis (PCA) of patches of the task CNN's features, and consider the distributions of the PCA loadings as additional experts. We extensively validate the method's efficacy on 5 MRI segmentation tasks (healthy tissues in 4 anatomical regions and lesion segmentation in 1 one anatomy), using data from 17 institutions, and on a MRI registration task, using data from 3 institutions. We find that the proposed FoE-based TTA is generically applicable in multiple tasks, and outperforms all previous TTA methods for lesion segmentation. For healthy tissue segmentation, the proposed method outperforms other task-agnostic TTA methods, but a previous TTA method which is specifically designed for segmentation performs the best for most of the tested datasets. Our implementation is publicly available here.